Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: allow NEP 42 dtypes to work with np.char (#22863)
This makes it possible for new-style NEP 42 string dtypes like ASCIIDType to work with the functions in np.char, this has leads to some mild modification (stricter behavior in bad paths). It will only work with dtypes with a scalar that subclasses str or bytes. I also assume that you can create instances of the user dtype from python like dtype_instance = CustomDType(size_in_bytes). This is a pretty big assumption about the API of the dtype, I'm not sure offhand how I can do this more portably or more safely. I also added a new macro, NPY_DT_is_user_defined, which checks dtype->type_num == -1, which is currently true for all custom dtypes using the experimental dtype API. This new macro is needed because NPY_DT_is_legacy will return false for np.void. This is only tested via the user dtypes currently.
- Loading branch information
Showing
6 changed files
with
111 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
String dtype instances can be created from the string abstract dtype classes | ||
---------------------------------------------------------------------------- | ||
It is now possible to create a string dtype instance with a size without | ||
using the string name of the dtype. For example, ``type(np.dtype('U'))(8)`` | ||
will create a dtype that is equivalent to ``np.dtype('U8')``. This feature | ||
is most useful when writing generic code dealing with string dtype | ||
classes. | ||
String functions in np.char are compatible with NEP 42 custom dtypes | ||
-------------------------------------------------------------------- | ||
Custom dtypes that represent unicode strings or byte strings can now be | ||
passed to the string functions in np.char. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
String dtype instances can be created from the string abstract dtype classes | ||
---------------------------------------------------------------------------- | ||
It is now possible to create a string dtype instance with a size without | ||
using the string name of the dtype. For example, ``type(np.dtype('U'))(8)`` | ||
will create a dtype that is equivalent to ``np.dtype('U8')``. This feature | ||
is most useful when writing generic code dealing with string dtype | ||
classes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters