Skip to content

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

Merged
seberg merged 5 commits intonumpy:mainfrom
ngoldbaum:string-dtype-creation
Jan 5, 2023
Merged

ENH: Create string dtype instances from the abstract dtype#22923
seberg merged 5 commits intonumpy:mainfrom
ngoldbaum:string-dtype-creation

Conversation

@ngoldbaum
Copy link
Copy Markdown
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
Copy Markdown
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.

@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 ngoldbaum force-pushed the string-dtype-creation branch from c7d7984 to 43626f2 Compare January 4, 2023 17:41
@ngoldbaum ngoldbaum force-pushed the string-dtype-creation branch from 43626f2 to 64395b4 Compare January 4, 2023 17:42
@ngoldbaum
Copy link
Copy Markdown
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
Copy Markdown
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.

}

if (size < 0) {
PyErr_Format(PyExc_ValueError,
Copy link
Copy Markdown
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.

3 participants