summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-05-27 15:14:39 -0700
committerSebastian Berg <sebastian@sipsolutions.net>2022-06-15 11:42:02 -0700
commit9a5c5e886a4222e769e2f251ec7705c565d0cc4f (patch)
tree04d8e561daa8b9bb160be43a575f79767e125ee6 /numpy/lib
parentffab4c45b3ad5264ff137b9f08490b6c986f9763 (diff)
downloadnumpy-9a5c5e886a4222e769e2f251ec7705c565d0cc4f.tar.gz
TST: Adapt percentile test to changed promotion
Promotion in percentile will now more aggressively preserve the input dtype for floating point types (rather than upgrading the type to at least float64).
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_function_base.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index bdcbef91d..b6ea12158 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -2954,11 +2954,11 @@ class TestPercentile:
H_F_TYPE_CODES = [(int_type, np.float64)
for int_type in np.typecodes["AllInteger"]
- ] + [(np.float16, np.float64),
- (np.float32, np.float64),
+ ] + [(np.float16, np.float16),
+ (np.float32, np.float32),
(np.float64, np.float64),
(np.longdouble, np.longdouble),
- (np.complex64, np.complex128),
+ (np.complex64, np.complex64),
(np.complex128, np.complex128),
(np.clongdouble, np.clongdouble),
(np.dtype("O"), np.float64)]
@@ -2980,10 +2980,15 @@ class TestPercentile:
expected,
input_dtype,
expected_dtype):
+ expected_dtype = np.dtype(expected_dtype)
+ if np.get_promotion_state() == "legacy":
+ expected_dtype = np.promote_types(expected_dtype, np.float64)
+
arr = np.asarray([15.0, 20.0, 35.0, 40.0, 50.0], dtype=input_dtype)
actual = np.percentile(arr, 40.0, method=method)
- np.testing.assert_almost_equal(actual, expected, 14)
+ np.testing.assert_almost_equal(
+ actual, expected_dtype.type(expected), 14)
if method in ["inverted_cdf", "closest_observation"]:
if input_dtype == "O":