32 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Invalid Python object.");
36 if (!PyDict_Check(pydata)) {
37 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Python object is not a dictionary.");
41 if (PyDict_Size(pydata) == 0) {
42 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary is empty.");
48 std::stringstream code;
49 code <<
"ROOT::Internal::RDF::MakeNumpyDataFrame(";
50 std::stringstream pyaddress;
51 auto pyvecs = PyDict_New();
53 code <<
"reinterpret_cast<PyObject*>(" << pyaddress.str() <<
"), ";
58 const auto size = PyObject_Size(pydata);
60 while (PyDict_Next(pydata, &pos, &key, &value)) {
63 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary key is not convertible to a string.");
71 PyErr_SetString(PyExc_RuntimeError,
72 (
"Object not convertible: Dictionary entry " + keystr +
" is not convertible with AsRVec.").c_str());
75 PyDict_SetItem(pyvecs, key, pyvec);
80 std::stringstream vecaddress;
82 code <<
"std::pair<std::string, " << vectype <<
"*>(\"" + keystr
83 <<
"\", reinterpret_cast<" << vectype+
"*>(" << vecaddress.str() <<
"))";
84 if (counter != size - 1) {
93 const auto err =
gInterpreter->Declare(
"#include \"ROOT/RNumpyDS.hxx\"");
95 PyErr_SetString(PyExc_RuntimeError,
"Failed to find \"ROOT/RNumpyDS.hxx\".");
98 const auto codeStr = code.str();
99 auto address = (
void*)
gInterpreter->Calc(codeStr.c_str());
100 const auto pythonOwns =
true;
104 if (PyObject_SetAttrString(pyobj,
"__data__", pyvecs)) {
105 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Failed to set dictionary as attribute __data__.");
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_Check
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
PyObject * MakeNumpyDataFrame(PyObject *self, PyObject *obj)
Make an RDataFrame from a dictionary of numpy arrays.
PyObject * AsRVec(PyObject *self, PyObject *obj)
Adopt memory of a Python object with array interface using an RVec.