Skip to content

DEPR: Enforce Rolling.validate/is_datetimelike/win_type deprecation #48838

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
Oct 21, 2022
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ Removal of prior version deprecations/changes
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`)
- Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)
- Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`)
- Removed deprecated :meth:`Timedelta.delta`, :meth:`Timedelta.is_populated`, and :attr:`Timedelta.freq` (:issue:`46430`, :issue:`46476`)
- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`)
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
Expand Down
37 changes: 2 additions & 35 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def __init__(
self.window = window
self.min_periods = min_periods
self.center = center
# TODO(2.0): Change this back to self.win_type once deprecation is enforced
self._win_type = win_type
self.win_type = win_type
self.axis = obj._get_axis_number(axis) if axis is not None else None
self.method = method
self._win_freq_i8: int | None = None
Expand All @@ -165,35 +164,6 @@ def __init__(
self._selection = selection
self._validate()

@property
def win_type(self):
if self._win_freq_i8 is not None:
warnings.warn(
"win_type will no longer return 'freq' in a future version. "
"Check the type of self.window instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return "freq"
return self._win_type

@property
def is_datetimelike(self) -> bool:
warnings.warn(
"is_datetimelike is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._win_freq_i8 is not None

def validate(self) -> None:
warnings.warn(
"validate is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._validate()

def _validate(self) -> None:
if self.center is not None and not is_bool(self.center):
raise ValueError("center must be a boolean")
Expand Down Expand Up @@ -331,10 +301,7 @@ def _gotitem(self, key, ndim, subset=None):

# we need to make a shallow copy of ourselves
# with the same groupby
with warnings.catch_warnings():
# TODO(2.0): Remove once win_type deprecation is enforced
warnings.filterwarnings("ignore", "win_type", FutureWarning)
kwargs = {attr: getattr(self, attr) for attr in self._attributes}
kwargs = {attr: getattr(self, attr) for attr in self._attributes}

selection = None
if subset.ndim == 2 and (
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/window/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,6 @@ def test_multiple_agg_funcs(func, window_size, expected_vals):
tm.assert_frame_equal(result, expected)


def test_is_datetimelike_deprecated():
s = Series(range(1)).rolling(1)
with tm.assert_produces_warning(FutureWarning):
assert not s.is_datetimelike


def test_validate_deprecated():
s = Series(range(1)).rolling(1)
with tm.assert_produces_warning(FutureWarning):
assert s.validate() is None


@pytest.mark.filterwarnings("ignore:min_periods:FutureWarning")
def test_dont_modify_attributes_after_methods(
arithmetic_win_operators, closed, center, min_periods, step
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/window/test_win_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ def test_consistent_win_type_freq(arg):
s.rolling(arg, win_type="freq")


def test_win_type_freq_return_deprecation():
def test_win_type_freq_return_none():
# GH 48838
freq_roll = Series(range(2), index=date_range("2020", periods=2)).rolling("2s")
with tm.assert_produces_warning(FutureWarning):
assert freq_roll.win_type == "freq"
assert freq_roll.win_type is None


@td.skip_if_no_scipy
Expand Down