summaryrefslogtreecommitdiff
path: root/numpy/ma/tests/test_extras.py
diff options
context:
space:
mode:
authorLaura Martens <laura.d.martens@icloud.com>2021-05-12 12:35:14 +0200
committerGitHub <noreply@github.com>2021-05-12 12:35:14 +0200
commitbb745921ac6c27d6caf9b76663668e5b9f28abac (patch)
treecb2e74269770ba9fcd6936ded25e9d2dceda75b1 /numpy/ma/tests/test_extras.py
parentfb586a4f5760efaae57a9251ed98c4ebd3edcdf8 (diff)
downloadnumpy-bb745921ac6c27d6caf9b76663668e5b9f28abac.tar.gz
BUG: fixed ma.average ignoring masked weights (#18960)
Closes #10438 Co-authored-by: mecopur <mecopur@outlook.com>
Diffstat (limited to 'numpy/ma/tests/test_extras.py')
-rw-r--r--numpy/ma/tests/test_extras.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index d237829cb..e735b9bc7 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -292,6 +292,23 @@ class TestAverage:
assert_almost_equal(wav1.real, expected1.real)
assert_almost_equal(wav1.imag, expected1.imag)
+ def test_masked_weights(self):
+ # Test with masked weights.
+ # (Regression test for https://github.com/numpy/numpy/issues/10438)
+ a = np.ma.array(np.arange(9).reshape(3, 3),
+ mask=[[1, 0, 0], [1, 0, 0], [0, 0, 0]])
+ weights_unmasked = masked_array([5, 28, 31], mask=False)
+ weights_masked = masked_array([5, 28, 31], mask=[1, 0, 0])
+
+ avg_unmasked = average(a, axis=0,
+ weights=weights_unmasked, returned=False)
+ expected_unmasked = np.array([6.0, 5.21875, 6.21875])
+ assert_almost_equal(avg_unmasked, expected_unmasked)
+
+ avg_masked = average(a, axis=0, weights=weights_masked, returned=False)
+ expected_masked = np.array([6.0, 5.576271186440678, 6.576271186440678])
+ assert_almost_equal(avg_masked, expected_masked)
+
class TestConcatenator:
# Tests for mr_, the equivalent of r_ for masked arrays.