diff options
author | pierregm <pierregm@localhost> | 2010-02-07 22:26:04 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2010-02-07 22:26:04 +0000 |
commit | 5bad51bf3afc9d2256e9f6a5a1883233b3065ddd (patch) | |
tree | 28448899d301f091b5eaab30ab52dbaa5f1634be /numpy/ma | |
parent | 5d87b02f5512c14238ddff3ae6982fe735be973a (diff) | |
download | numpy-5bad51bf3afc9d2256e9f6a5a1883233b3065ddd.tar.gz |
* Force the fill_value of a structured masked array to be defined (bug #1332)
Diffstat (limited to 'numpy/ma')
-rw-r--r-- | numpy/ma/core.py | 3 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index f85f9145a..3ab29ae6b 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2733,6 +2733,9 @@ class MaskedArray(ndarray): # But don't run the check unless we have something to check.... if fill_value is not None: _data._fill_value = _check_fill_value(fill_value, _data.dtype) + elif names_: + # Named fields: make sure _fill_value is initialized + _data._fill_value = _check_fill_value(None, _data.dtype) # Process extra options .. if hard_mask is None: _data._hardmask = getattr(data, '_hardmask', False) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index ada858b01..b849d0c48 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1440,6 +1440,7 @@ class TestFillingValues(TestCase): def test_fillvalue_individual_fields(self): "Test setting fill_value on individual fields" ndtype = [('a', int), ('b', int)] + # Explicit fill_value a = array(zip([1, 2, 3], [4, 5, 6]), fill_value=(-999, -999), dtype=ndtype) f = a._fill_value @@ -1449,6 +1450,12 @@ class TestFillingValues(TestCase): assert_equal(tuple(a.fill_value), (10, -999)) a.fill_value['b'] = -10 assert_equal(tuple(a.fill_value), (10, -10)) + # Implicit fill_value + t = array(zip([1, 2, 3], [4, 5, 6]), dtype=[('a', int), ('b', int)]) + tt = t['a'] + tt.set_fill_value(10) + assert_equal(tt._fill_value, np.array(10)) + assert_equal(tuple(t.fill_value), (10, default_fill_value(0))) #------------------------------------------------------------------------------ |