10000 deprecation warning for `nonzero(0d_array)` not shown · Issue #19216 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

deprecation warning for nonzero(0d_array) not shown #19216

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

Closed
rgommers opened this issue Jun 10, 2021 · 3 comments
Closed

deprecation warning for nonzero(0d_array) not shown #19216

rgommers opened this issue Jun 10, 2021 · 3 comments

Comments

@rgommers
Copy link
Member

This is odd, it works as expected for the .nonzero method, but not for the np.nonzero function:

>>> np.__version__
'1.20.2'

>>> x = np.array(3)
>>> x.ndim
0
>>> np.nonzero(x)
(array([0]),)
>>> x.nonzero()
<ipython-input-5-68292516afaf>:1: DeprecationWarning: Calling nonzero on 0d arrays is deprecated, as it behaves surprisingly. Use `atleast_1d(arr).nonzero()` if the old behavior was intended.
  x.nonzero()
(array([0]),)

I haven't looked into why this happens.

The deprecation happened in 1.17.0, see gh-13708.

@seberg
Copy link
Member
seberg commented Jun 10, 2021

Interesting, setting warnings.simplefilter("always") makes it show up.

It would seem that some import statement causes the warning to given (and ignored). And because the stacklevel will point into NumPy, the default "once" showing of the warning will mean it is always hidden.

And since this even happens on a vanilla python session, that bad import statement is likely within NumPy itself...

@seberg
Copy link
Member
seberg commented Jun 10, 2021

Oh, I am wrong. It must be the special DeprecationWarning logic, trying to not show the warning if it appears to be originating in a dependency (in this case NumPy itself due to the stacklevel).

Even using python -Wonce causes the warning to be shown. The only option we have is to use VisibleDeprecationWarning for a bit. Libraries should be OK, since they hopefully ensure they notice all deprecation warnings at some point.

@rgommers
Copy link
Member Author
rgommers commented Dec 7, 2022

I think we can close this, the explanation sounds right and we can expire this deprecation at some point.

@rgommers rgommers closed this as completed Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0