Skip to content

ENH: Always produce a consistent shape in the result of argwhere #13610

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

Merged
merged 1 commit into from
Sep 6, 2019

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented May 23, 2019

Previously this would return 1d indices even though the array is zero-d.

Also update the docs to remove recommending the use of tranpose(nonzero(a)).

Inspired by #13522 - we can't easily fix nonzero, but we can fix downstream uses.

@eric-wieser
Copy link
Member Author

Looking downstream - scipy imports argwhere then never uses it, and matplotlib uses it but only on a 1d array.

I suspect the only users actually affected by this will be the ones who have code that is currently broken on 0d arrays anyway.

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

One small comment about the docstring changes.

But a larger one overall: isn't it really better to just change nonzero? See #13522 (comment)


transpose(nonzero(a))

To group the indices by element, rather than dimension, use `argwhere`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably good to also mention argwhere in the See also section.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Lets maybe put this off to 1.18? I like the change, but hope it is not too bold. But then the current 0-D behaviour is pretty broken. Tests also look good. It definitely will need a release note though.

We do have a .. versionchanged:: tag, which I think we should use in the notes Section here.

@seberg seberg added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label May 23, 2019
@eric-wieser
Copy link
Member Author

If we're deprecating nonzero for this case, we probably need an implementation here that does not use it.

@eric-wieser
Copy link
Member Author

Lets maybe put this off to 1.18?

Don't think there's any way for me to write release notes if we do that. Opening #13707 to track solutions to that problem.

@eric-wieser
Copy link
Member Author

Updated with a release note

@mattip
Copy link
Member

mattip commented Sep 4, 2019

Failing:

File "/home/travis/build/numpy/numpy/builds/venv/lib/python3.6/site-packages/numpy/core/shape_base.py", line 438, in <module>

    _size = getattr(_nx.size, '__wrapped__', _nx.size)

AttributeError: module 'numpy.core.numeric' has no attribute 'size'

@eric-wieser
Copy link
Member Author

Yep, caught out by a rebase. Had to tweak the imports some more to avoid cycles.

@mattip
Copy link
Member

mattip commented Sep 4, 2019

Builds are failing:

../../builds/venv/lib/python3.6/site-packages/numpy/core/shape_base.py:531: in _atleast_nd

    return array(a, ndmin=ndim, copy=False, subok=True)

E   NameError: name 'array' is not defined

Previously this would return 1d indices even though the array is zero-d.

Note that using atleast1d inside numeric required an import change to avoid a circular import.
@seberg
Copy link
Member

seberg commented Sep 6, 2019

Looks all good to me. Lets give it a shot for 1.18. The quest for making 0D arrays not weird continues :).

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