Skip to content

Commit 199624d

Browse files
authored
DEPR Rename keyword "quantile" to "q" in Rolling.quantile (#53216)
* deprecated 'quantile' arg in Rolling.quantile * renamed keyword 'quantile' to 'q' in Rolling.quantile * fixed test * docstring modified, removed unnecessary descriptions and typos * resolved conversations * deprecate on Expanding as well * resolved conversations; renamed in parent
1 parent 64e88e3 commit 199624d

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Deprecations
219219
~~~~~~~~~~~~
220220
- Deprecated 'broadcast_axis' keyword in :meth:`Series.align` and :meth:`DataFrame.align`, upcast before calling ``align`` with ``left = DataFrame({col: left for col in right.columns}, index=right.index)`` (:issue:`51856`)
221221
- Deprecated 'method', 'limit', and 'fill_axis' keywords in :meth:`DataFrame.align` and :meth:`Series.align`, explicitly call ``fillna`` on the alignment results instead (:issue:`51856`)
222+
- Deprecated 'quantile' keyword in :meth:`Rolling.quantile` and :meth:`Expanding.quantile`, renamed as 'q' instead (:issue:`52550`)
222223
- Deprecated :meth:`.DataFrameGroupBy.apply` and methods on the objects returned by :meth:`.DataFrameGroupBy.resample` operating on the grouping column(s); select the columns to operate on after groupby to either explicitly include or exclude the groupings and avoid the ``FutureWarning`` (:issue:`7155`)
223224
- Deprecated :meth:`.Groupby.all` and :meth:`.GroupBy.any` with datetime64 or :class:`PeriodDtype` values, matching the :class:`Series` and :class:`DataFrame` deprecations (:issue:`34479`)
224225
- Deprecated :meth:`Categorical.to_list`, use ``obj.tolist()`` instead (:issue:`51254`)

pandas/core/window/expanding.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
Callable,
88
)
99

10-
from pandas.util._decorators import doc
10+
from pandas.util._decorators import (
11+
deprecate_kwarg,
12+
doc,
13+
)
1114

1215
from pandas.core.indexers.objects import (
1316
BaseIndexer,
@@ -575,6 +578,9 @@ def kurt(self, numeric_only: bool = False):
575578
"""
576579
quantile : float
577580
Quantile to compute. 0 <= quantile <= 1.
581+
582+
.. deprecated:: 2.1.0
583+
This will be renamed to 'q' in a future version.
578584
interpolation : {{'linear', 'lower', 'higher', 'midpoint', 'nearest'}}
579585
This optional parameter specifies the interpolation method to use,
580586
when the desired quantile lies between two data points `i` and `j`:
@@ -596,14 +602,15 @@ def kurt(self, numeric_only: bool = False):
596602
aggregation_description="quantile",
597603
agg_method="quantile",
598604
)
605+
@deprecate_kwarg(old_arg_name="quantile", new_arg_name="q")
599606
def quantile(
600607
self,
601-
quantile: float,
608+
q: float,
602609
interpolation: QuantileInterpolation = "linear",
603610
numeric_only: bool = False,
604611
):
605612
return super().quantile(
606-
quantile=quantile,
613+
q=q,
607614
interpolation=interpolation,
608615
numeric_only=numeric_only,
609616
)

pandas/core/window/rolling.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import pandas._libs.window.aggregations as window_aggregations
2929
from pandas.compat._optional import import_optional_dependency
3030
from pandas.errors import DataError
31-
from pandas.util._decorators import doc
31+
from pandas.util._decorators import (
32+
deprecate_kwarg,
33+
doc,
34+
)
3235

3336
from pandas.core.dtypes.common import (
3437
ensure_float64,
@@ -1601,18 +1604,18 @@ def kurt(self, numeric_only: bool = False):
16011604

16021605
def quantile(
16031606
self,
1604-
quantile: float,
1607+
q: float,
16051608
interpolation: QuantileInterpolation = "linear",
16061609
numeric_only: bool = False,
16071610
):
1608-
if quantile == 1.0:
1611+
if q == 1.0:
16091612
window_func = window_aggregations.roll_max
1610-
elif quantile == 0.0:
1613+
elif q == 0.0:
16111614
window_func = window_aggregations.roll_min
16121615
else:
16131616
window_func = partial(
16141617
window_aggregations.roll_quantile,
1615-
quantile=quantile,
1618+
quantile=q,
16161619
interpolation=interpolation,
16171620
)
16181621

@@ -2384,6 +2387,9 @@ def kurt(self, numeric_only: bool = False):
23842387
"""
23852388
quantile : float
23862389
Quantile to compute. 0 <= quantile <= 1.
2390+
2391+
.. deprecated:: 2.1.0
2392+
This will be renamed to 'q' in a future version.
23872393
interpolation : {{'linear', 'lower', 'higher', 'midpoint', 'nearest'}}
23882394
This optional parameter specifies the interpolation method to use,
23892395
when the desired quantile lies between two data points `i` and `j`:
@@ -2424,14 +2430,15 @@ def kurt(self, numeric_only: bool = False):
24242430
aggregation_description="quantile",
24252431
agg_method="quantile",
24262432
)
2433+
@deprecate_kwarg(old_arg_name="quantile", new_arg_name="q")
24272434
def quantile(
24282435
self,
2429-
quantile: float,
2436+
q: float,
24302437
interpolation: QuantileInterpolation = "linear",
24312438
numeric_only: bool = False,
24322439
):
24332440
return super().quantile(
2434-
quantile=quantile,
2441+
q=q,
24352442
interpolation=interpolation,
24362443
numeric_only=numeric_only,
24372444
)

pandas/tests/window/test_expanding.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,10 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype):
707707
op2 = getattr(expanding2, kernel)
708708
expected = op2(*arg2, numeric_only=numeric_only)
709709
tm.assert_series_equal(result, expected)
710+
711+
712+
def test_keyword_quantile_deprecated():
713+
# GH #52550
714+
ser = Series([1, 2, 3, 4])
715+
with tm.assert_produces_warning(FutureWarning):
716+
ser.expanding().quantile(quantile=0.5)

pandas/tests/window/test_rolling_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def test_center_reindex_frame(frame, roll_func, kwargs, minp, fill_value):
340340
lambda x: x.rolling(window=10, min_periods=5).var(),
341341
lambda x: x.rolling(window=10, min_periods=5).skew(),
342342
lambda x: x.rolling(window=10, min_periods=5).kurt(),
343-
lambda x: x.rolling(window=10, min_periods=5).quantile(quantile=0.5),
343+
lambda x: x.rolling(window=10, min_periods=5).quantile(q=0.5),
344344
lambda x: x.rolling(window=10, min_periods=5).median(),
345345
lambda x: x.rolling(window=10, min_periods=5).apply(sum, raw=False),
346346
lambda x: x.rolling(window=10, min_periods=5).apply(sum, raw=True),

pandas/tests/window/test_rolling_quantile.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,10 @@ def test_center_reindex_frame(frame, q):
173173
)
174174
frame_rs = frame.rolling(window=25, center=True).quantile(q)
175175
tm.assert_frame_equal(frame_xp, frame_rs)
176+
177+
178+
def test_keyword_quantile_deprecated():
179+
# GH #52550
180+
s = Series([1, 2, 3, 4])
181+
with tm.assert_produces_warning(FutureWarning):
182+
s.rolling(2).quantile(quantile=0.4)

0 commit comments

Comments
 (0)