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

ENH: Create string dtype instances from the abstract dtype #22923

Merged
merged 5 commits into from
Jan 5, 2023

Conversation

ngoldbaum
Copy link
Member

Following up from #22863 (comment), this makes it possible to create string dtype instances from an abstract string DTypeMeta.

Should I support any additional arguments or keywords to __new__ besides size? Possibly byteorder?

Should this be documented somewhere? If so, where?

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, a few comments, but generally I am happy with adding this.

Documenting this seems awkward (even the release note...) until we have a clear spelling for type(np.dtype('U')).
After that, it seems pretty obvious to document it in the class.

numpy/core/src/multiarray/dtypemeta.c Outdated Show resolved Hide resolved
numpy/core/src/multiarray/dtypemeta.c Outdated Show resolved Hide resolved
numpy/core/src/multiarray/dtypemeta.c Outdated Show resolved Hide resolved
doc/release/upcoming_changes/22863.new_feature.rst Outdated Show resolved Hide resolved
@seberg seberg added the 62 - Python API Changes or additions to the Python API. Mailing list should usually be notified. label Jan 3, 2023
@ngoldbaum
Copy link
Member Author

Thanks for the comments! I used npy_mul_sizes_with_overflow to deal with the overflow based on other examples in numpy. Let me know if you spot any issues with my usage.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy, although that swap would be nice (adding a test would also be nice maybe, since 2**30 hits it).

I will assume nobody minds this tiny API addition, so planning to merge soon.

numpy/core/src/multiarray/dtypemeta.c Show resolved Hide resolved
}

if (size < 0) {
PyErr_Format(PyExc_ValueError,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to value error, because I thought even the other ones make more sense that way. But then, it shares the error with other paths, so only did this one.

If anyone doesn't like, happy to follow up. Will merge once tests are done, thanks Nathan.

@seberg seberg merged commit 3b5ba53 into numpy:main Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - Enhancement 62 - Python API Changes or additions to the Python API. Mailing list should usually be notified.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants