Skip to content

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

Merged
seberg merged 1 commit into
numpy:masterfrom
eric-wieser:argwhere
Sep 6, 2019
Merged

seberg merged 1 commit into
numpy:masterfrom
eric-wieser:argwhere

Conversation

@eric-wieser

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

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)

Comment thread numpy/core/fromnumeric.py Outdated

Copy link
Copy Markdown
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.

@seberg seberg left a comment

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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Updated with a release note

@mattip

mattip commented Sep 4, 2019

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

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

@mattip

mattip commented Sep 4, 2019

Copy link
Copy Markdown
Member

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

seberg commented Sep 6, 2019

Copy link
Copy Markdown
Member

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