[Numpy-svn] r8093 - in trunk/numpy/ma: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Feb 7 17:26:04 EST 2010


Author: pierregm
Date: 2010-02-07 16:26:04 -0600 (Sun, 07 Feb 2010)
New Revision: 8093

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
* Force the fill_value of a structured masked array to be defined (bug #1332)

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2010-02-07 21:13:40 UTC (rev 8092)
+++ trunk/numpy/ma/core.py	2010-02-07 22:26:04 UTC (rev 8093)
@@ -2733,6 +2733,9 @@
         # 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)

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2010-02-07 21:13:40 UTC (rev 8092)
+++ trunk/numpy/ma/tests/test_core.py	2010-02-07 22:26:04 UTC (rev 8093)
@@ -1440,6 +1440,7 @@
     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 @@
         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)))
 
 #------------------------------------------------------------------------------
 




More information about the Numpy-svn mailing list