From 6b8d55e66e532d66e1701ad039b4cda306839b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Sun, 17 Jul 2022 05:58:53 -0700 Subject: BUG: Fix masked median multiple masked arrays (#21999) Fixed issue that occurs when trying to take the median of a list of masked arrays. Added a check to see if the input is a list then converts to a masked array. See issue #10757 for more information. Co-authored-by: jsclose --- numpy/ma/tests/test_extras.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'numpy/ma/tests') diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index 04bf8cfc2..3637accc3 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -1160,6 +1160,25 @@ class TestMedian: o[2] = np.nan assert_(type(np.ma.median(o.astype(object))), float) + def test_list_of_masked_array(self): + data1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) + masked1 = np.ma.masked_where(data1 == 4, data1) + data2 = np.array([[8, 7, 6, 5], [4, 3, 2, 1]]) + masked2 = np.ma.masked_where(data2 == 4, data2) + list = [masked1, masked2] + median_masked_list = np.ma.median(list, axis=0).data + assert_equal(median_masked_list, + np.array([[4.5, 4.5, 4.5, 5], [5, 4.5, 4.5, 4.5]])) + + def test_list_of_masked_array_no_axis(self): + data1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) + masked1 = np.ma.masked_where(data1 == 2, data1) + data2 = np.array([[8, 7, 6, 5], [4, 3, 2, 1]]) + masked2 = np.ma.masked_where(data2 == 5, data2) + list = [masked1, masked2] + median_masked_list = np.ma.median(list) + assert_equal(median_masked_list, 4.5) + class TestCov: -- cgit v1.2.1