Skip to content

Commit ad0260c

Browse files
committed
Fix quantile
1 parent 87d4d20 commit ad0260c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

pandas/core/frame.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13059,16 +13059,14 @@ def quantile(
1305913059
interpolation=interpolation,
1306013060
method=method,
1306113061
)
13062-
if method == "single":
13063-
res = res_df.iloc[0]
13064-
else:
13065-
# cannot directly iloc over sparse arrays
13066-
res = res_df.T.iloc[:, 0]
13062+
res = res_df.iloc[0]
1306713063
if axis == 1 and len(self) == 0:
1306813064
# GH#41544 try to get an appropriate dtype
13069-
dtype = find_common_type(list(self.dtypes))
13070-
if needs_i8_conversion(dtype):
13071-
return res.astype(dtype)
13065+
dtype = "float64"
13066+
cdtype = find_common_type(list(self.dtypes))
13067+
if needs_i8_conversion(cdtype):
13068+
dtype = cdtype
13069+
return res.astype(dtype)
1307213070
return res
1307313071

1307413072
q = Index(q, dtype=np.float64)

pandas/tests/frame/methods/test_quantile.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,7 @@ def test_quantile_empty_no_rows_floats(self, interp_method):
658658
tm.assert_frame_equal(res, exp)
659659

660660
res = df.quantile(0.5, axis=1, interpolation=interpolation, method=method)
661-
dtype = "float64" if interpolation == "linear" else "object"
662-
exp = Series([], index=[], name=0.5, dtype=dtype)
661+
exp = Series([], index=[], dtype="float64", name=0.5)
663662
tm.assert_series_equal(res, exp)
664663

665664
res = df.quantile([0.5], axis=1, interpolation=interpolation, method=method)
@@ -714,8 +713,7 @@ def test_quantile_empty_no_columns(self, interp_method):
714713
result = df.quantile(
715714
0.5, numeric_only=True, interpolation=interpolation, method=method
716715
)
717-
dtype = "float64" if interpolation == "linear" else "object"
718-
expected = Series([], index=[], name=0.5, dtype=dtype)
716+
expected = Series([], index=[], name=0.5, dtype=np.float64)
719717
expected.index.name = "captain tightpants"
720718
tm.assert_series_equal(result, expected)
721719

0 commit comments

Comments
 (0)