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

numpy masked array regression in 1.13.0rc1 #9121

Closed
jswhit opened this issue May 15, 2017 · 3 comments
Closed

numpy masked array regression in 1.13.0rc1 #9121

jswhit opened this issue May 15, 2017 · 3 comments

Comments

@jswhit
Copy link

jswhit commented May 15, 2017

With version 1.12.1 the following script

from numpy import ma, __version__
print __version__
x = ma.array(1, mask=True)
print x[...],type(x[...])

produced

1.12.1
-- <class 'numpy.ma.core.MaskedConstant'>

With 1.13.0rc1 I get

1.13.0rc1
-- <class 'numpy.ma.core.MaskedArray'>

This means that x[...] is ma.masked returns False in 1.13, when it used to return True.

So it appears that the behaviour of scalar masked arrays has changed. This is causing test failures in netcdf4-python.

@jswhit jswhit changed the title numpy masked array regression in 1.13.rc0 numpy masked array regression in 1.13.0rc1 May 15, 2017
@ahaldane
Copy link
Member

This was an intentional change in #8905, but we didn't note it in the release notes. (Probably we should).

I think the new behavior is more correct because in general indexing with [...] gives back an array, and converts scalars to arrays:

>>> np.array(3)[...]
array(3)
>>> np.int64(3)[...]
array(3)
>>> np.arange(2)[...]
array([0, 1])

if you goal is to convert a 0d array to a scalar, I think you should replace x[...] in your code by x[()]. Indexing with () is the usual way of converting 0d-arrays to scalars, and in a sense is the opposite of indexing with ....

>>> x = np.ma.array(1, mask=True)
>>> x[()] is np.ma.masked
True

@jswhit
Copy link
Author

jswhit commented May 15, 2017

OK - thanks for the clarification. Close if you wish.

@charris
Copy link
Member

charris commented May 15, 2017

@ahaldane Probably worth a note in the 1.9.0 release notes under compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants