Skip to content
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

Merged

Conversation

seberg
Copy link
Member

@seberg seberg commented Jul 24, 2020

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 gh-16939

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
@seberg
Copy link
Member Author

seberg commented Jul 24, 2020

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.

@eric-wieser
Copy link
Member

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 */
Copy link
Member

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? ;)

@charris
Copy link
Member

charris commented Jul 25, 2020

Let's give it a shot. Thanks Sebastian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValueError: invalid __array_struct__ when assigning to object-dtype ndarray
3 participants