Skip to content

Commit 6059db1

Browse files
authored
Merge pull request numpy#26071 from ngoldbaum/fix-maximum-minimum
BUG: fix logic error in stringdtype maximum/minimum ufunc
2 parents f4f1ac8 + 9be279c commit 6059db1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

numpy/_core/src/umath/stringdtype_ufuncs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ minimum_maximum_strided_loop(PyArrayMethod_Context *context, char *const data[],
429429
npy_packed_static_string *sout = (npy_packed_static_string *)out;
430430
int cmp = _compare(in1, in2, in1_descr, in2_descr);
431431
if (cmp == 0 && (in1 == out || in2 == out)) {
432-
continue;
432+
goto next_step;
433433
}
434434
if ((cmp < 0) ^ invert) {
435435
// if in and out are the same address, do nothing to avoid a
@@ -449,6 +449,8 @@ minimum_maximum_strided_loop(PyArrayMethod_Context *context, char *const data[],
449449
}
450450
}
451451
}
452+
453+
next_step:
452454
in1 += in1_stride;
453455
in2 += in2_stride;
454456
out += out_stride;

numpy/_core/tests/test_stringdtype.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ def test_ufuncs_minmax(string_list, ufunc_name, func, use_out):
668668
res = ufunc(arr, arr)
669669

670670
assert_array_equal(uarr, res)
671+
assert_array_equal(getattr(arr, ufunc_name)(), func(string_list))
672+
673+
674+
def test_max_regression():
675+
arr = np.array(['y', 'y', 'z'], dtype="T")
676+
assert arr.max() == 'z'
671677

672678

673679
@pytest.mark.parametrize("use_out", [True, False])

0 commit comments

Comments
 (0)