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

More robust/flexible numpy dtype and ufuncs #52

Open
benbovy opened this issue Oct 8, 2024 · 3 comments
Open

More robust/flexible numpy dtype and ufuncs #52

benbovy opened this issue Oct 8, 2024 · 3 comments

Comments

@benbovy
Copy link
Owner

benbovy commented Oct 8, 2024

Not sure that we need this now, but here is an implementation of Numpy user dtypes and ufuncs with pybind11.

@jorisvandenbossche
Copy link
Collaborator

I also assume that it will require numpy>=2?

It might certainly be nice to at some point use a custom user-defined numpy dtype, instead of the object dtype that can hold anything.

But the current setup works quite OK I think (and you get a nice error message if some value in the object array is not a Geography), so I would also say to first focus on getting a minimal viable package with the current approach, and we can always improve this later.

@benbovy
Copy link
Owner Author

benbovy commented Oct 9, 2024

I also assume that it will require numpy>=2?

Not sure about that, the commit I linked above is from 6 years ago. I also don't really know whether there would be a more elegant, numpy 2 solution nowadays.

It might certainly be nice to at some point use a custom user-defined numpy dtype, instead of the object dtype that can hold anything. But the current setup works quite OK I think

Yes definitely! Just wanted to link this here as a useful reference in case we might eventually need it. The ufunc feature is also relevant (perhaps more than user dtypes) to work around the limitations of pybind11::vectorize.

@jorisvandenbossche
Copy link
Collaborator

I also assume that it will require numpy>=2?

Not sure about that, the commit I linked above is from 6 years ago. I also don't really know whether there would be a more elegant, numpy 2 solution nowadays.

Ah, I hadn't checked the date of the commit ;)
Yes, nowadays numpy exposes a newer API to properly create custom dtypes (and expose those to the user in Python), so I assume the linked code might need to be updated for that.

I am also not entirely sure if the custom dtype already supports object dtype (I know when we explored an initial version of it two years ago for shapely, that wasn't yet the case)

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

No branches or pull requests

2 participants