Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Provide pybind11 type casters #37062

Open
pitrou opened this issue Aug 8, 2023 · 6 comments
Open

[Python] Provide pybind11 type casters #37062

pitrou opened this issue Aug 8, 2023 · 6 comments

Comments

@pitrou
Copy link
Member

pitrou commented Aug 8, 2023

Describe the enhancement requested

pybind11 allows defining custom type casters to translate between C++ classes and Python objects:
https://pybind11.readthedocs.io/en/stable/advanced/cast/custom.html

We already provide a C++ API to wrap and unwrap PyArrow objects from/to PyObject pointers. It would probably nicer to pybind11 users if we also provided a more automated facility.

A draft implementation of some type casters was done by @timkpaine here:
https://github.com/timkpaine/arrow-cpp-python-nocopy/blob/main/src/apn-python/caster.hpp

Component(s)

Python

@pitrou
Copy link
Member Author

pitrou commented Aug 8, 2023

@timkpaine
Copy link
Contributor

I copied this from @maartenbreddels https://github.com/vaexio/vaex-arrow-ext/blob/master/src/caster.hpp

It’s definitely useful to have this pybind utility, the only thing I think would be important is to make a big (bigger?) warning about ABI compatibility. Every 6 months or so I forget that if I’m writing my own C++ library that I want to bind out into python to transfer arrows back and forth, I can’t necessarily just naively use the pyarrow interfaces.

@pitrou
Copy link
Member Author

pitrou commented Aug 22, 2023

Also cc @danepitkin

@alippai
Copy link
Contributor

alippai commented Aug 28, 2023

Shouldn't Apache Arrow use nanobind instead if possible? I guess the Arrow project is modern enough to use it (Python 3.8+, C++17 required)

@timkpaine
Copy link
Contributor

s/shouldn't/couldn't

I think pybind is preferable given its popularity, but such an effort in pybind should be easy enough to translate into other binding libraries.

@pitrou
Copy link
Member Author

pitrou commented Aug 30, 2023

Shouldn't Apache Arrow use nanobind instead if possible? I guess the Arrow project is modern enough to use it (Python 3.8+, C++17 required)

PyArrow uses neither. This issue is about better supporting users of pybind11, not using it in PyArrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants