Skip to content

Commit 18bdb2e

Browse files
authored
Merge pull request #30713 from charris/backport-30710
BUG: Fixup the quantile promotion fixup
2 parents 41dd751 + 7a278da commit 18bdb2e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

numpy/lib/_function_base_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4576,7 +4576,7 @@ def _get_gamma(virtual_indexes, previous_indexes, method):
45764576
gamma = method["fix_gamma"](gamma, virtual_indexes)
45774577
# Ensure both that we have an array, and that we keep the dtype
45784578
# (which may have been matched to the input array).
4579-
return np.asanyarray(gamma)
4579+
return np.asanyarray(gamma, dtype=virtual_indexes.dtype)
45804580

45814581

45824582
def _lerp(a, b, t, out=None):

numpy/lib/tests/test_function_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,6 +3941,9 @@ def test_q_strong_promotion(self, method):
39413941
a = np.array([1, 2, 3, 4, 5], dtype=np.float32)
39423942
value = np.percentile(a, np.float64(50), method=method)
39433943
assert value.dtype == np.float64
3944+
# Check that we don't do accidental promotion either:
3945+
value = np.percentile(a, np.float32(50), method=method)
3946+
assert value.dtype == np.float32
39443947

39453948

39463949
class TestQuantile:
@@ -4379,6 +4382,9 @@ def test_q_strong_promotion(self, method):
43794382
a = np.array([1, 2, 3, 4, 5], dtype=np.float32)
43804383
value = np.quantile(a, np.float64(0.5), method=method)
43814384
assert value.dtype == np.float64
4385+
# Check that we don't do accidental promotion either:
4386+
value = np.quantile(a, np.float32(0.5), method=method)
4387+
assert value.dtype == np.float32
43824388

43834389

43844390
class TestLerp:

0 commit comments

Comments
 (0)