-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: vectorize
truncates string outputs to 1 character, even with explicitly-specified otypes
#23442
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
Comments
otypes
vectorize
truncates string outputs to 1 character, even with explicitly-specified otypes
Thanks for reporting the issue, @cgobat. Edit: I removed my previous misguided comment. The size of any string types specified in
The lengths 16 and 32 have been discarded, and only the type code The actual output size of the strings will depend on the code path taken internally. If
If
|
Thanks for looking into this, @WarrenWeckesser. Any ideas on how to proceed towards a resolution? Is a documentation update called for in the meantime? |
is there some news about that? |
The issue arises when signature is given as this particular path is chosen: As part of this,
[EDIT] Coupled with this change #26270, the size of |
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue:
When a user creates a
vectorize
object from a function that returns a string as its output, and specifies the function's output type(s) using theotypes
argument, string typecode specifiers (e.g."U10"
for a 10-character string) of any length cause the returned strings to be truncated to 1 character (i.e.np.dtype("<U1")
. The same things happens with bytes (typecode"S"
, with any length specified). In order to make it work, one must either not specify anyotypes
(omit the argument), or use"O"
to get a genericobject
dtype.It seems this issue is possibly related to #2485 and/or StackOverflow: How to explicitly specify the output's string length in numpy.vectorize, but I can't say for sure. It seems odd that
otypes
ignores explicit length declarations.Reproduce the code example:
Output:
Runtime information:
np.__version__
is 1.24.2.sys.version
isOutput of
np.show_runtime()
is:Context for the issue:
This issue can cause problems because if users want to specify their function's
otypes
explicitly, they are forced to use"O"
, which other operations that expect to see string dtype outputs (rather thannp.object
) may not be able to handle without additional processing.The text was updated successfully, but these errors were encountered: