Skip to content

Add round-trip casts between string and (u)int dtypes #72

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

Merged
merged 6 commits into from
Jun 22, 2023

Conversation

ngoldbaum
Copy link
Member

Making a PR to solicit feedback before I do this again for the float dtypes.

I could have done this without using the python C API but this approach seemed less finicky than dealing with serializing ints as strings in a portable way in C. FWIW, numpy currently does the equivalent cast for the unicode dtype by going through numpy scalars. In principle in the future we could drop the GIL requirement and do this in a more low-level way.

There's a lot of copy/paste here. It's very possible we've reached or are long past the point where writing this in C++ would be a good idea. I guess if this code is going to end up living in numpy eventually it's not problematic to add a build dependency on a C++ toolchain.

@ngoldbaum
Copy link
Member Author

There's a lot of copy/paste here.

It turns out I can avoid almost all of the copy/paste using preprocessor macros, see latest commit.

@ngoldbaum
Copy link
Member Author

I'm happy with the state of this now, if anyone has any comments or suggestions I'll take care of it in a followup.

@ngoldbaum ngoldbaum merged commit 79bfa3b into numpy:main Jun 22, 2023
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

Successfully merging this pull request may close these issues.

1 participant