diff options
author | Gerrit Holl <g.holl@reading.ac.uk> | 2015-12-02 11:55:36 +0000 |
---|---|---|
committer | Gerrit Holl <g.holl@reading.ac.uk> | 2015-12-03 17:45:49 +0000 |
commit | 53facf327c7b2949a5f31c308fd66b0b1f24b615 (patch) | |
tree | bbb7633baec061278d2b19bb876bbc3b46c0cc8c /numpy/lib/tests/test_packbits.py | |
parent | b3a8994a2a3c89c00ac4a95e01cd0888b72fd9af (diff) | |
download | numpy-53facf327c7b2949a5f31c308fd66b0b1f24b615.tar.gz |
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.
Diffstat (limited to 'numpy/lib/tests/test_packbits.py')
0 files changed, 0 insertions, 0 deletions