Repository navigation
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.
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
arrto 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