Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a87031f

Browse files
authored
Merge pull request #21993 from rcomer/ma-minimum-fix
BUG: fix ma.minimum.reduce with axis keyword
2 parents af44af7 + b8c6d09 commit a87031f

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

numpy/ma/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6875,6 +6875,8 @@ def reduce(self, target, axis=np._NoValue, **kwargs):
68756875

68766876
if m is nomask:
68776877
t = self.f.reduce(target.view(np.ndarray), **kwargs)
6878+
if isinstance(t, ndarray):
6879+
t = MaskedArray(t, mask=nomask)
68786880
else:
68796881
target = target.filled(
68806882
self.fill_value_func(target)).view(type(target))

numpy/ma/tests/test_core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,18 @@ def test_minmax_reduce(self):
12351235
b = np.maximum.reduce(a)
12361236
assert_equal(b, 3)
12371237

1238+
def test_minmax_reduce_axis(self):
1239+
# Test np.min/maximum.reduce along an axis for 2D array
1240+
import numpy as np
1241+
data = [[0, 1, 2, 3, 4, 9], [5, 5, 0, 9, 3, 3]]
1242+
mask = [[0, 0, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0]]
1243+
a = array(data, mask=mask)
1244+
1245+
expected = array([0, 3], mask=False)
1246+
result = np.minimum.reduce(a, axis=1)
1247+
1248+
assert_array_equal(result, expected)
1249+
12381250
def test_minmax_funcs_with_output(self):
12391251
# Tests the min/max functions with explicit outputs
12401252
mask = np.random.rand(12).round()

0 commit comments

Comments
 (0)