Skip to content

Commit b69e88c

Browse files
committed
MAINT: Also adopt q handling from the main quantile/percnetile to na version
1 parent 3ccd1cd commit b69e88c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

numpy/lib/_nanfunctions_impl.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,8 @@ def nanpercentile(
13751375
if a.dtype.kind == "c":
13761376
raise TypeError("a must be an array of real numbers")
13771377

1378-
q = np.true_divide(q, 100.0)
1379-
# undo any decay that the ufunc performed (see gh-13105)
1380-
q = np.asanyarray(q)
1378+
q = np.true_divide(q, a.dtype.type(100) if a.dtype.kind == "f" else 100)
1379+
q = np.asanyarray(q) # undo any decay that the ufunc performed (see gh-13105)
13811380
if not fnb._quantile_is_valid(q):
13821381
raise ValueError("Percentiles must be in the range [0, 100]")
13831382
return _nanquantile_unchecked(
@@ -1538,7 +1537,12 @@ def nanquantile(
15381537
if a.dtype.kind == "c":
15391538
raise TypeError("a must be an array of real numbers")
15401539

1541-
q = np.asanyarray(q)
1540+
# Use dtype of array if possible (e.g., if q is a python int or float).
1541+
if isinstance(q, (int, float)) and a.dtype.kind == "f":
1542+
q = np.asanyarray(q, dtype=np.result_type(a, q))
1543+
else:
1544+
q = np.asanyarray(q)
1545+
15421546
if not fnb._quantile_is_valid(q):
15431547
raise ValueError("Quantiles must be in the range [0, 1]")
15441548
return _nanquantile_unchecked(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy