14#include "../../cppyy/CPyCppyy/src/CPyCppyy.h"
15#include "../../cppyy/CPyCppyy/src/CPPInstance.h"
16#include "../../cppyy/CPyCppyy/src/ProxyWrappers.h"
35 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Invalid Python object.");
39 if (!PyDict_Check(pydata)) {
40 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Python object is not a dictionary.");
44 if (PyDict_Size(pydata) == 0) {
45 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary is empty.");
51 std::stringstream code;
52 code <<
"ROOT::Internal::RDF::MakeNumpyDataFrame(";
53 std::stringstream pyaddress;
54 auto pyvecs = PyDict_New();
59 code <<
"reinterpret_cast<PyObject*>(" << pyaddress.str() <<
"), ";
64 const auto size = PyObject_Size(pydata);
66 while (PyDict_Next(pydata, &pos, &key, &
value)) {
69 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Dictionary key is not convertible to a string.");
77 PyErr_SetString(PyExc_RuntimeError,
78 (
"Object not convertible: Dictionary entry " + keystr +
" is not convertible with AsRVec.").c_str());
81 PyDict_SetItem(pyvecs, key, pyvec);
86 std::stringstream vecaddress;
91 code <<
"std::pair<std::string, " << vectype <<
"*>(\"" + keystr
92 <<
"\", reinterpret_cast<" << vectype+
"*>(" << vecaddress.str() <<
"))";
93 if (counter !=
size - 1) {
102 const auto err =
gInterpreter->Declare(
"#include \"ROOT/RNumpyDS.hxx\"");
104 PyErr_SetString(PyExc_RuntimeError,
"Failed to find \"ROOT/RNumpyDS.hxx\".");
107 const auto codeStr = code.str();
108 auto address = (
void*)
gInterpreter->Calc(codeStr.c_str());
109 const auto pythonOwns =
true;
113 if (PyObject_SetAttrString(pyobj,
"__data__", pyvecs)) {
114 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.