Skip to content

DEPR Rename keyword "quantile" to "q" in Rolling.quantile #53216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Deprecations
~~~~~~~~~~~~
- 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`)
- 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`)
- Deprecated 'quantile' keyword in :meth:`Rolling.quantile`, renamed as 'q' instead (:issue:`52550`)
- 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`)
- Deprecated :meth:`.Groupby.all` and :meth:`.GroupBy.any` with datetime64 or :class:`PeriodDtype` values, matching the :class:`Series` and :class:`DataFrame` deprecations (:issue:`34479`)
- Deprecated :meth:`Categorical.to_list`, use ``obj.tolist()`` instead (:issue:`51254`)
Expand Down
19 changes: 14 additions & 5 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import pandas._libs.window.aggregations as window_aggregations
from pandas.compat._optional import import_optional_dependency
from pandas.errors import DataError
from pandas.util._decorators import doc
from pandas.util._decorators import (
deprecate_kwarg,
doc,
)

from pandas.core.dtypes.common import (
ensure_float64,
Expand Down Expand Up @@ -2382,8 +2385,8 @@ def kurt(self, numeric_only: bool = False):
create_section_header("Parameters"),
dedent(
"""
quantile : float
Quantile to compute. 0 <= quantile <= 1.
q : float
Quantile to compute. 0 <= q <= 1.
interpolation : {{'linear', 'lower', 'higher', 'midpoint', 'nearest'}}
This optional parameter specifies the interpolation method to use,
when the desired quantile lies between two data points `i` and `j`:
Expand All @@ -2394,6 +2397,11 @@ def kurt(self, numeric_only: bool = False):
* higher: `j`.
* nearest: `i` or `j` whichever is nearest.
* midpoint: (`i` + `j`) / 2.
cols : float
Alias for keyword 'q', kwargs only.

.. deprecated:: 2.1.0
Use keyword 'q' instead.
"""
).replace("\n", "", 1),
kwargs_numeric_only,
Expand Down Expand Up @@ -2424,14 +2432,15 @@ def kurt(self, numeric_only: bool = False):
aggregation_description="quantile",
agg_method="quantile",
)
@deprecate_kwarg(old_arg_name="quantile", new_arg_name="q")
def quantile(
self,
quantile: float,
q: float,
interpolation: QuantileInterpolation = "linear",
numeric_only: bool = False,
):
return super().quantile(
quantile=quantile,
quantile=q,
interpolation=interpolation,
numeric_only=numeric_only,
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/window/test_rolling_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_center_reindex_frame(frame, roll_func, kwargs, minp, fill_value):
lambda x: x.rolling(window=10, min_periods=5).var(),
lambda x: x.rolling(window=10, min_periods=5).skew(),
lambda x: x.rolling(window=10, min_periods=5).kurt(),
lambda x: x.rolling(window=10, min_periods=5).quantile(quantile=0.5),
lambda x: x.rolling(window=10, min_periods=5).quantile(q=0.5),
lambda x: x.rolling(window=10, min_periods=5).median(),
lambda x: x.rolling(window=10, min_periods=5).apply(sum, raw=False),
lambda x: x.rolling(window=10, min_periods=5).apply(sum, raw=True),
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/window/test_rolling_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,11 @@ def test_center_reindex_frame(frame, q):
)
frame_rs = frame.rolling(window=25, center=True).quantile(q)
tm.assert_frame_equal(frame_xp, frame_rs)


def test_keyword_quantile_deprecated():
# GH #52550
# deprecate keyword 'quantile' of Rolling.quantile, rename as 'q'
s = Series([1, 2, 3, 4])
with tm.assert_produces_warning(FutureWarning):
s.rolling(2).quantile(quantile=0.4)