-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 size-one ragged array coercion #16943
DEP: Deprecate size-one ragged array coercion #16943
Conversation
Previously, code such as: ``` np.array([0, np.array([0])], dtype=np.int64) ``` worked by discovering the array as having a shape of `(2,)` and then using `int(np.array([0]))` (which currently succeeds). This is also a ragged array, and thus deprecated here earlier on. (As a detail, in the new code the assignment should occur as an array assignment and not using the `__int__`/`__float__` Python protocols.) Two details to note: 1. This still skips the deprecation for sequences which are not array-likes. We assume that sequences will always fail the conversion to a number. 2. The conversion to a number (or string, etc.) may still fail after the DeprecationWarning is given. This is not ideal, but narrowing it down seems tedious, since the actual assignment happens in a later step. I.e. `np.array([0, np.array([None])], dtype=np.int64)` will give the warning, but then fail anyway, since the array cannot be assigned. Closes numpygh-16939
I am honestly a bit surprised this missed the old ragged-array deprecation, but I don't recall exactly, maybe the old ragged array deprecation was wired into the dtype discovery chunk and not activated when a dtype is passed in. |
Ping @nschloe, since this is a much weaker form of something you wanted to deprecate. |
} | ||
|
||
if (deprecate_single_element_ragged) { | ||
/* Deprecated 2019-07-24, NumPy 1.20 */ |
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.
Are you sure this is the right date? ;)
Let's give it a shot. Thanks Sebastian. |
Previously, code such as:
worked by discovering the array as having a shape of
(2,)
andthen using
int(np.array([0]))
(which currently succeeds).This is also a ragged array, and thus deprecated here earlier on.
(As a detail, in the new code the assignment should occur as
an array assignment and not using the
__int__
/__float__
Python protocols.)
Two details to note:
array-likes. We assume that sequences will always fail the
conversion to a number.
after the DeprecationWarning is given. This is not ideal, but
narrowing it down seems tedious, since the actual assignment
happens in a later step.
I.e.
np.array([0, np.array([None])], dtype=np.int64)
will givethe warning, but then fail anyway, since the array cannot be
assigned.
Closes gh-16939