DEP: Deprecate size-one ragged array coercion#16943
Merged
charris merged 2 commits intonumpy:masterfrom Jul 25, 2020
Merged
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
Member
Author
|
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. |
Member
|
Ping @nschloe, since this is a much weaker form of something you wanted to deprecate. |
eric-wieser
reviewed
Jul 24, 2020
| } | ||
|
|
||
| if (deprecate_single_element_ragged) { | ||
| /* Deprecated 2019-07-24, NumPy 1.20 */ |
Member
There was a problem hiding this comment.
Are you sure this is the right date? ;)
seberg
commented
Jul 24, 2020
Member
|
Let's give it a shot. Thanks Sebastian. |
This was referenced Jul 26, 2020
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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