From 715daa97ad716da52ada07eb10cc37b314428311 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 27 Jun 2017 00:32:17 +0100 Subject: BUG: Fix gh-8069 Fill values were not correctly calculated for subdtypes, instead returning `None` --- numpy/ma/core.py | 7 ++++++- numpy/ma/tests/test_core.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'numpy/ma') diff --git a/numpy/ma/core.py b/numpy/ma/core.py index e091baa22..d0b18fb3a 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -277,7 +277,12 @@ def _recursive_extremum_fill_value(ndtype, extremum): fval = _recursive_extremum_fill_value(ndtype[name], extremum) deflist.append(fval) return tuple(deflist) - return extremum[ndtype] + elif ndtype.subdtype: + subtype, shape = ndtype.subdtype + subval = _recursive_extremum_fill_value(subtype, extremum) + return np.full(shape, subval) + else: + return extremum[ndtype] def _extremum_fill_value(obj, extremum, extremum_name): diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index bba8f2cb7..26099455d 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1879,6 +1879,15 @@ class TestFillingValues(TestCase): assert_equal(test[1][1], maximum_fill_value(a['B']['BB'])) assert_equal(test[1], maximum_fill_value(a['B'])) + def test_extremum_fill_value_subdtype(self): + a = array(([2, 3, 4],), dtype=[('value', np.int8, 3)]) + + test = minimum_fill_value(a) + assert_equal(test[0], np.full(3, minimum_fill_value(a['value']))) + + test = maximum_fill_value(a) + assert_equal(test[0], np.full(3, maximum_fill_value(a['value']))) + def test_fillvalue_individual_fields(self): # Test setting fill_value on individual fields ndtype = [('a', int), ('b', int)] -- cgit v1.2.1