Skip to content

DEP: Deprecate nonzero(0d) in favor of calling atleast_1d explicitly - #13708

Merged
mattip merged 2 commits into
numpy:masterfrom
eric-wieser:deprecate-nonzero
Jun 13, 2019
Merged

mattip merged 2 commits into
numpy:masterfrom
eric-wieser:deprecate-nonzero

Conversation

@eric-wieser

Copy link
Copy Markdown
Member

This is a weird enough corner case that either:

  • No one is running into it, and downstream code is broken on 0d arrays anyway
  • People already have hacks in place to work around it:
    • Calling nonzero but handling the result specially if the array was 0d. We want to dissuade this in case we change the result of nonzero to be better in future.
    • Not calling nonzero at all if the array is zerod (such as by using atleast1d). These users are unaffected.

Follows up on #13632

This is a weird enough corner case that either:
* No one is running into it, and downstream code is broken on 0d arrays anyway
* People already have hacks in place to work around it:
  * Calling `nonzero` but handling the result specially if the array was 0d. We want to dissuade this in case we change the result of nonzero to be better in future.
  * Not calling `nonzero` at all if the array is zerod (such as by using `atleast1d`). These users are unaffected.
@eric-wieser

Copy link
Copy Markdown
Member Author

LGTM CI seems stuck

@eric-wieser eric-wieser closed this Jun 7, 2019
@eric-wieser eric-wieser reopened this Jun 7, 2019
@eric-wieser

Copy link
Copy Markdown
Member Author

@jhelie: Any idea why this PR is getting duplicate LGTM runs with different icons?

@mattip

mattip commented Jun 7, 2019

Copy link
Copy Markdown
Member

There should be some mention of this in the docstring for nonzero, with an example.

Should this deprecation hit the mailing list?

@eric-wieser

Copy link
Copy Markdown
Member Author

Probably a good idea to hit the list with this, although I don't expect anyone to care.

Which section of the nonzero docstring do you think I should modify?

@mattip

mattip commented Jun 7, 2019

Copy link
Copy Markdown
Member

See commit 19f0c77 for a suggestion, feel free to delete/modify

Comment thread numpy/core/fromnumeric.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be mentioning this next to the transpose(nonzero(a)) example, I think the change in #13610 does a better job of that section.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think 0-d arrays are important enough to justify their own section here, but we should have a passing mention for them somewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The positioning of this statement is particularly confusing because it seems to suggest that nonzero(atleast_1d(x)) is a substitute for transpose(nonzero(x))

@jhelie

jhelie commented Jun 7, 2019 •

Copy link
Copy Markdown
Contributor

@jhelie: Any idea why this PR is getting duplicate LGTM runs with different icons?

@eric-wieser Our guess is that it might have been a transient issue due to when the update to the new App occurred. It shouldn't happen again (I see the latest analysis is not duplicated) but please do ping me again if it does.

@mhvk

mhvk commented Jun 7, 2019

Copy link
Copy Markdown
Contributor

Obviously also affects the method, but that already refers to the function documentation.

I'm happy with just going for this.

Also indicate that the current behavior in this case is deprecated.

This also removes the advice to use `a[nonzero(a)]` or `transpose(nonzero(a))`, for which there are better spellings.
@eric-wieser

Copy link
Copy Markdown
Member Author

@mattip: Adjusted the docstring to be closer to what I had in mind.

@eric-wieser eric-wieser added this to the 1.17.0 release milestone Jun 12, 2019
@eric-wieser

Copy link
Copy Markdown
Member Author

Milestoning as 1.17.0 because I'd like not to have to update the documentation to say 1.18 unless we consciously decide not to put this in.

@mhvk

mhvk commented Jun 12, 2019

Copy link
Copy Markdown
Contributor

As noted above, I'm happy to put this in. Will wait another day just in case someone objects.

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.

4 participants