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 nonzero(0d) in favor of calling atleast_1d explicitly #13708

Merged
merged 2 commits into from
Jun 13, 2019

Conversation

eric-wieser
Copy link
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
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
Member Author

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

@mattip
Copy link
Member

mattip commented Jun 7, 2019

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

mattip commented Jun 7, 2019

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

@@ -1774,7 +1774,8 @@ def nonzero(a):
transpose(nonzero(a))

The result of this is always a 2-D array, with a row for
each non-zero element.
each non-zero element. If there is concern the input may be a 0-d array,
use `nonzero(atleast_1d(a))` instead.
Copy link
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
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
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
Copy link
Contributor

jhelie commented Jun 7, 2019

@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
Copy link
Contributor

mhvk commented Jun 7, 2019

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
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
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
Copy link
Contributor

mhvk commented Jun 12, 2019

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.

None yet

4 participants