-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DEP: Deprecate coercion to subarray dtypes #17419
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
DEP: Deprecate coercion to subarray dtypes #17419
Conversation
When coercing to subarray dtypes, e.g. using `np.array(obj, dtype)`, but also `arr.astype(dtype)`, the behaviour was only well defined with tuple inputs, but not with array-like inputs. In particular, `arr.astype(dtype)` had arguably surprising behaviour of not converting by element, but rather attempting (and often failing) to broadcast `arr` to the result array with added dimensions. This deprecates all of these cases, the main issue would be for users relying on stranger inputs with broadcasted tuples contained in sequences: ``` np.array([((0, 1), (1, 2)), ((2,),)], dtype='(2,2)f4') ``` In most cases, where the tuples have the correct output shape, the new base dtype can be directly used since the discovered shape should match. However, there is no work-around for the above case. Closes numpygh-17173
9c33587
to
e31ae7f
Compare
In a sense, the arguably correct solution would be to only do the "dimension absorbing" step after doing all the assignment (reshaping/viewing the array before returning). The problem is that this changes the behaviour of current array-likes the same way as in the
since it returns uninitialized memory :(. |
* WARNING: Do not use this function, it exists purely to support a deprecated | ||
* code path. | ||
*/ | ||
static int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case it isn't obvious from the comment. Do not review this function, it is a straight copy from the 1.19.x branch.
Putting this in. We may need to revert the deprecation if real use cases arise. |
Thanks @seberg |
Hello. |
When coercing to subarray dtypes, e.g. using
np.array(obj, dtype)
,but also
arr.astype(dtype)
, the behaviour was only well definedwith tuple inputs, but not with array-like inputs.
In particular,
arr.astype(dtype)
had arguably surprising behaviourof not converting by element, but rather attempting (and often failing)
to broadcast
arr
to the result array with added dimensions.This deprecates all of these cases, the main issue would be for users
relying on stranger inputs with broadcasted tuples contained in
sequences:
In most cases, where the tuples have the correct output shape,
the new base dtype can be directly used since the discovered shape
should match.
However, there is no work-around for the above case.
Closes gh-17173