Category : pybind11

I’m trying to create a std::vector<py::handle> in C++ to unittest a C++ function that receives such a vector. I need to create a vector of integers (py::int_), floats (py::float_) and strings (py::str). I’ve tried things like: auto int1 = py::int_(1); std::vector<py::handle> values = {py::handle(int1)}; Or: auto int1 = py::int_(1); std::vector<py::handle> values = {py::handle(int1.ptr())}; But this ..

Read more

I have a C++ class MyClass that is binded to python using pybind11. Thus MyClass resides in python module named mymodule. That means from python I can do: import mymodule my_class = mymodule.MyClass() Also I have C++ class YourClass: class YourClass { public: YourCPPObject() {} std::string foo(MyClass* myClass){ myClass->getName(); }; }; YourClass must be binded ..

Read more

What’s the def order of pybind11 function/method arguments and doc-strings ? For example I want to define a class method like this: PYBIND11_MODULE(my_module, m) { m.doc() = "my pybind11 module"; py::class_<MyClass>(m, "MyClass") .def("my_method", &MyClass::my_method, py::arg("a"), py::arg("b"), "print a and b"); } I want to define two args a and b, and doc-string "print a and ..

Read more

#include <pybind11/pybind11.h> #include <Python.h> #include <iostream> #include <arrow/python/pyarrow.h> #include <arrow/table.h> // Convert pyarrow table to native C++ object and print its contents void print_table(PyObject* py_table) { // convert pyobject to table auto status = arrow::py::unwrap_table(py_table); if (!status.ok()) { std::cout << "Error converting pyarrow table to arrow table" << std::endl; return; } std::shared_ptr<arrow::Table> table = status.ValueOrDie(); ..

Read more

I’m trying to pass a pyarrow table to c++ via pybind11. In this example I’m simply trying to print the number of rows of a pyarrow table passed from python. #include <pybind11/pybind11.h> #include <Python.h> #include <iostream> #include <arrow/python/pyarrow.h> // Convert pyarrow table to native C++ object and print its contents void print_table(PyObject* py_table) { // ..

Read more