33 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Invalid Python object.");
37 if (!PyDict_Check(pydata)) {
38 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Python object is not a dictionary.");
42 if (PyDict_Size(pydata) == 0) {
43 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary is empty.");
49 std::stringstream code;
50 code <<
"ROOT::Internal::RDF::MakeNumpyDataFrame(";
51 std::stringstream pyaddress;
52 auto pyvecs = PyDict_New();
57 code <<
"reinterpret_cast<PyObject*>(" << pyaddress.str() <<
"), ";
62 const auto size = PyObject_Size(pydata);
64 while (PyDict_Next(pydata, &pos, &key, &
value)) {
67 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary key is not convertible to a string.");
75 PyErr_SetString(PyExc_RuntimeError,
76 (
"Object not convertible: Dictionary entry " + keystr +
" is not convertible with AsRVec.").c_str());
79 PyDict_SetItem(pyvecs, key, pyvec);
84 std::stringstream vecaddress;
89 code <<
"std::pair<std::string, " << vectype <<
"*>(\"" + keystr
90 <<
"\", reinterpret_cast<" << vectype+
"*>(" << vecaddress.str() <<
"))";
91 if (counter !=
size - 1) {
100 const auto err =
gInterpreter->Declare(
"#include \"ROOT/RNumpyDS.hxx\"");
102 PyErr_SetString(PyExc_RuntimeError,
"Failed to find \"ROOT/RNumpyDS.hxx\".");
105 const auto codeStr = code.str();
106 auto address = (
void*)
gInterpreter->Calc(codeStr.c_str());
107 const auto pythonOwns =
true;
111 if (PyObject_SetAttrString(pyobj,
"__data__", pyvecs)) {
112 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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
PyObject * MakeNumpyDataFrameImpl(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.