[Numpy-svn] [numpy/numpy] 53facf: BUG/TST: Fix for #6724, make numpy.ma.mvoid consis...
GitHub
noreply at github.com
Fri Dec 4 14:49:38 EST 2015
Branch: refs/heads/master
Home: https://github.com/numpy/numpy
Commit: 53facf327c7b2949a5f31c308fd66b0b1f24b615
https://github.com/numpy/numpy/commit/53facf327c7b2949a5f31c308fd66b0b1f24b615
Author: Gerrit Holl <g.holl at reading.ac.uk>
Date: 2015-12-03 (Thu, 03 Dec 2015)
Changed paths:
M numpy/ma/core.py
M numpy/ma/tests/test_core.py
Log Message:
-----------
BUG/TST: Fix for #6724, make numpy.ma.mvoid consistent with numpy.void
Make indexing on numpy.ma.mvoid consistent with indexing on numpy.void.
Changes behaviour in rare cases (see below). Fixes #6724. Sometimes,
indexing ma.mvoid results in a non-scalar mask. For example, dimension
increases if indexing with a multi-dimensional field. Previously, this
led to a ValueError (truth value ambiguous). With this commit, indexing
now returns an ma.masked_array so that there is no loss of information.
Note that there is a precedence for returning from void to array. Z =
zeros((2,), dtype="(2,)i2,(2,)i2"), then Z[0] is a void, but Z[0][0]
and Z[0]["f1"] are array. This commit therefore implements behaviouk
such that numpy.ma.mvoid is consistent with numpy.void.
Also adds a related test.
The behaviour changes in cases where for a masked array `X`, X.dtype["A"]
is multidimensional but size 1, such as in the example below. Any case
where X.dtype["A"] is multidimensional but with size>1 would previously
fail.
Old behaviour:
In [15]: X = ma.masked_array(data=[([0],)], mask=[([False],)],
dtype=[("A", "(1,1)i2", (1,1))])
In [16]: X[0]["A"]
Out[16]: array([[[[0]]]], dtype=int16)
In [17]: X = ma.masked_array(data=[([0],)], mask=[([True],)],
dtype=[("A", "(1,1)i2", (1,1))])
In [18]: X[0]["A"]
Out[18]: masked
New behaviour:
In [1]: X = ma.masked_array(data=[([0],)], mask=[([False],)],
dtype=[("A", "(1,1)i2", (1,1))])
In [2]: X[0]["A"]
Out[2]:
masked_array(data =
[[[[0]]]],
mask =
[[[[False]]]],
fill_value = [[[[16959]]]])
In [3]: X = ma.masked_array(data=[([0],)], mask=[([True],)],
dtype=[("A", "(1,1)i2", (1,1))])
In [4]: X[0]["A"]
Out[4]:
masked_array(data =
[[[[--]]]],
mask =
[[[[ True]]]],
fill_value = [[[[16959]]]])
The new behaviour is more consistent with indexing the data themselves:
In [7]: X.data[0]["A"]
Out[7]: array([[[[0]]]], dtype=int16)
In theory, this change in behaviour can break code, but I would consider
it very unlikely.
Commit: 3cc797e5107d5f3fe812b0ccdc9bc96f107f0b20
https://github.com/numpy/numpy/commit/3cc797e5107d5f3fe812b0ccdc9bc96f107f0b20
Author: Charles Harris <charlesr.harris at gmail.com>
Date: 2015-12-04 (Fri, 04 Dec 2015)
Changed paths:
M numpy/ma/core.py
M numpy/ma/tests/test_core.py
Log Message:
-----------
Merge pull request #6763 from gerritholl/structured_multidim_masked_array_mvoid_alt
BUG/TST: Fix for #6724, make numpy.ma.mvoid consistent with numpy.void
Compare: https://github.com/numpy/numpy/compare/c890b10a8ade...3cc797e5107d
More information about the Numpy-svn
mailing list