Skip to content

Commit

Permalink
[CLN] call __finalize__ in quantile (pandas-dev#47183)
Browse files Browse the repository at this point in the history
* remove unreachable code in DataFrame.quantile

* add test for increased coverage
  • Loading branch information
theOehrly authored and yehoshuadimarsky committed Jul 13, 2022
1 parent f716151 commit 4494d5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10936,10 +10936,8 @@ def quantile(
if needs_i8_conversion(cdtype):
dtype = cdtype

if is_list_like(q):
res = self._constructor([], index=q, columns=cols, dtype=dtype)
return res.__finalize__(self, method="quantile")
return self._constructor_sliced([], index=cols, name=q, dtype=dtype)
res = self._constructor([], index=q, columns=cols, dtype=dtype)
return res.__finalize__(self, method="quantile")

res = data._mgr.quantile(qs=q, axis=1, interpolation=interpolation)

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@
operator.methodcaller("quantile", numeric_only=False),
),
),
pytest.param(
(
pd.DataFrame,
({"A": [np.datetime64("2022-01-01"), np.datetime64("2022-01-02")]},),
operator.methodcaller("quantile", numeric_only=True),
),
),
(
pd.DataFrame,
({"A": [1]}, [pd.Period("2000", "D")]),
Expand Down

0 comments on commit 4494d5e

Please sign in to comment.