File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -1375,9 +1375,8 @@ def nanpercentile(
1375
1375
if a .dtype .kind == "c" :
1376
1376
raise TypeError ("a must be an array of real numbers" )
1377
1377
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)
1381
1380
if not fnb ._quantile_is_valid (q ):
1382
1381
raise ValueError ("Percentiles must be in the range [0, 100]" )
1383
1382
return _nanquantile_unchecked (
@@ -1538,7 +1537,12 @@ def nanquantile(
1538
1537
if a .dtype .kind == "c" :
1539
1538
raise TypeError ("a must be an array of real numbers" )
1540
1539
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
+
1542
1546
if not fnb ._quantile_is_valid (q ):
1543
1547
raise ValueError ("Quantiles must be in the range [0, 1]" )
1544
1548
return _nanquantile_unchecked (
You can’t perform that action at this time.
0 commit comments