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 all 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` and :meth:`Expanding.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
13 changes: 10 additions & 3 deletions pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
Callable,
)

from pandas.util._decorators import doc
from pandas.util._decorators import (
deprecate_kwarg,
doc,
)

from pandas.core.indexers.objects import (
BaseIndexer,
Expand Down Expand Up @@ -575,6 +578,9 @@ def kurt(self, numeric_only: bool = False):
"""
quantile : float
Quantile to compute. 0 <= quantile <= 1.

.. deprecated:: 2.1.0
This will be renamed to 'q' in a future version.
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 @@ -596,14 +602,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,
q=q,
interpolation=interpolation,
numeric_only=numeric_only,
)
Expand Down
21 changes: 14 additions & 7 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 @@ -1601,18 +1604,18 @@ def kurt(self, numeric_only: bool = False):

def quantile(
self,
quantile: float,
q: float,
interpolation: QuantileInterpolation = "linear",
numeric_only: bool = False,
):
if quantile == 1.0:
if q == 1.0:
window_func = window_aggregations.roll_max
elif quantile == 0.0:
elif q == 0.0:
window_func = window_aggregations.roll_min
else:
window_func = partial(
window_aggregations.roll_quantile,
quantile=quantile,
quantile=q,
interpolation=interpolation,
)

Expand Down Expand Up @@ -2384,6 +2387,9 @@ def kurt(self, numeric_only: bool = False):
"""
quantile : float
Quantile to compute. 0 <= quantile <= 1.

.. deprecated:: 2.1.0
This will be renamed to 'q' in a future version.
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 Down Expand Up @@ -2424,14 +2430,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,
q=q,
interpolation=interpolation,
numeric_only=numeric_only,
)
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/window/test_expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,10 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype):
op2 = getattr(expanding2, kernel)
expected = op2(*arg2, numeric_only=numeric_only)
tm.assert_series_equal(result, expected)


def test_keyword_quantile_deprecated():
# GH #52550
ser = Series([1, 2, 3, 4])
with tm.assert_produces_warning(FutureWarning):
ser.expanding().quantile(quantile=0.5)
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
7 changes: 7 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,10 @@ 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
s = Series([1, 2, 3, 4])
with tm.assert_produces_warning(FutureWarning):
s.rolling(2).quantile(quantile=0.4)