BUG: Fix concatenation when the output is "S" or "U" #18063
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #18052.
Previously, the dtype was used, this now assumes that we want to
cast to a string of (unknown) length. This is a simplified version
of what happens in
np.array()
orarr.astype()
(it does neverinspect the values, e.g. for object casts).
This is more complex as I would like, and with the refactor of
ResultType and similar can be cleaned up a bit more hopefully.
Note that currently, object to "S" or "U" casts simply return
length 64 strings, but with the new version, this will be an error
(although the error message probably needs improvement).
This is a behaviour inherited from other places however.
The issue here is that NumPy 1.20 is just broken if you pass
dtype="U"
in concatenate. Unfortunately, this is about as "minimal" as I could think of (some things around it should be cleaned up also in the new code paths). Things are simply fairly complicated if you have "flexible dtypes" or DType (type/class) in my way of thinking about it...There is of course more inanity here, e.g.
concatenate
usesresult_type
which uses value-based casting for 0-D objects, but there is not much to do about it right at this instance.