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();
56 code <<
"reinterpret_cast<PyObject*>(" << pyaddress.str() <<
"), ";
61 const auto size = PyObject_Size(pydata);
63 while (PyDict_Next(pydata, &pos, &key, &value)) {
66 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary key is not convertible to a string.");
74 PyErr_SetString(PyExc_RuntimeError,
75 (
"Object not convertible: Dictionary entry " + keystr +
" is not convertible with AsRVec.").c_str());
78 PyDict_SetItem(pyvecs, key, pyvec);
83 std::stringstream vecaddress;
88 code <<
"std::pair<std::string, " << vectype <<
"*>(\"" + keystr
89 <<
"\", reinterpret_cast<" << vectype+
"*>(" << vecaddress.str() <<
"))";
90 if (counter !=
size - 1) {
99 const auto err =
gInterpreter->Declare(
"#include \"ROOT/RNumpyDS.hxx\"");
101 PyErr_SetString(PyExc_RuntimeError,
"Failed to find \"ROOT/RNumpyDS.hxx\".");
104 const auto codeStr = code.str();
105 auto address = (
void*)
gInterpreter->Calc(codeStr.c_str());
106 const auto pythonOwns =
true;
110 if (PyObject_SetAttrString(pyobj,
"__data__", pyvecs)) {
111 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Failed to set dictionary as attribute __data__.");
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_Check
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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.