From c0b180014bcd6b51891057e4711b18351509ca3d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 26 Oct 2022 02:35:06 -0700 Subject: [PATCH] DEPR: Remove get_offset, infer_freq warn param (#49314) --- doc/source/whatsnew/v2.0.0.rst | 2 + .../tseries/frequencies/test_inference.py | 12 ++--- pandas/tests/tseries/offsets/test_fiscal.py | 44 ------------------- pandas/tseries/frequencies.py | 44 ++----------------- 4 files changed, 10 insertions(+), 92 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 50b8af5e8d1e2..c068b2733cc7a 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -219,6 +219,8 @@ Removal of prior version deprecations/changes - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) - Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`) - Disallow passing abbreviations for ``orient`` in :meth:`DataFrame.to_dict` (:issue:`32516`) +- Removed ``get_offset`` in favor of :func:`to_offset` (:issue:`30340`) +- Removed the ``warn`` keyword in :func:`infer_freq` (:issue:`45947`) - Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`) - Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`) - Removed the ``pandas.datetime`` submodule (:issue:`30489`) diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index ea9a09ff2d65c..eebed6a4c27d3 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -10,6 +10,7 @@ DAYS, MONTHS, ) +from pandas._libs.tslibs.offsets import _get_offset from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG from pandas.compat import is_platform_windows @@ -447,7 +448,7 @@ def test_series_datetime_index(freq): @pytest.mark.parametrize( "offset_func", [ - frequencies._get_offset, + _get_offset, lambda freq: date_range("2011-01-01", periods=5, freq=freq), ], ) @@ -507,18 +508,13 @@ def test_legacy_offset_warnings(offset_func, freq): def test_ms_vs_capital_ms(): - left = frequencies._get_offset("ms") - right = frequencies._get_offset("MS") + left = _get_offset("ms") + right = _get_offset("MS") assert left == offsets.Milli() assert right == offsets.MonthBegin() -def test_infer_freq_warn_deprecated(): - with tm.assert_produces_warning(FutureWarning): - frequencies.infer_freq(date_range(2022, periods=3), warn=False) - - def test_infer_freq_non_nano(): arr = np.arange(10).astype(np.int64).view("M8[s]") dta = DatetimeArray._simple_new(arr, dtype=arr.dtype) diff --git a/pandas/tests/tseries/offsets/test_fiscal.py b/pandas/tests/tseries/offsets/test_fiscal.py index d0801b2cede29..26937c348d9c8 100644 --- a/pandas/tests/tseries/offsets/test_fiscal.py +++ b/pandas/tests/tseries/offsets/test_fiscal.py @@ -6,17 +6,13 @@ from dateutil.relativedelta import relativedelta import pytest -from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG - from pandas import Timestamp -import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( WeekDay, assert_is_on_offset, assert_offset_equal, ) -from pandas.tseries.frequencies import get_offset from pandas.tseries.offsets import ( FY5253, FY5253Quarter, @@ -54,46 +50,6 @@ def test_get_offset_name(): ) -def test_get_offset(): - with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG): - with tm.assert_produces_warning(FutureWarning): - get_offset("gibberish") - with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG): - with tm.assert_produces_warning(FutureWarning): - get_offset("QS-JAN-B") - - pairs = [ - ("RE-N-DEC-MON", makeFY5253NearestEndMonth(weekday=0, startingMonth=12)), - ("RE-L-DEC-TUE", makeFY5253LastOfMonth(weekday=1, startingMonth=12)), - ( - "REQ-L-MAR-TUE-4", - makeFY5253LastOfMonthQuarter( - weekday=1, startingMonth=3, qtr_with_extra_week=4 - ), - ), - ( - "REQ-L-DEC-MON-3", - makeFY5253LastOfMonthQuarter( - weekday=0, startingMonth=12, qtr_with_extra_week=3 - ), - ), - ( - "REQ-N-DEC-MON-3", - makeFY5253NearestEndMonthQuarter( - weekday=0, startingMonth=12, qtr_with_extra_week=3 - ), - ), - ] - - for name, expected in pairs: - with tm.assert_produces_warning(FutureWarning): - offset = get_offset(name) - assert offset == expected, ( - f"Expected {repr(name)} to yield {repr(expected)} " - f"(actual: {repr(offset)})" - ) - - class TestFY5253LastOfMonth: offset_lom_sat_aug = makeFY5253LastOfMonth(1, startingMonth=8, weekday=WeekDay.SAT) offset_lom_sat_sep = makeFY5253LastOfMonth(1, startingMonth=9, weekday=WeekDay.SAT) diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index a7fe2da703908..1cf9fb9a85b37 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -1,7 +1,5 @@ from __future__ import annotations -import warnings - import numpy as np from pandas._libs.algos import unique_deltas @@ -23,16 +21,13 @@ month_position_check, ) from pandas._libs.tslibs.offsets import ( - BaseOffset, DateOffset, Day, - _get_offset, to_offset, ) from pandas._libs.tslibs.parsing import get_rule_month from pandas._typing import npt from pandas.util._decorators import cache_readonly -from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import ( is_datetime64_dtype, @@ -102,30 +97,11 @@ def get_period_alias(offset_str: str) -> str | None: return _offset_to_period_map.get(offset_str, None) -def get_offset(name: str) -> BaseOffset: - """ - Return DateOffset object associated with rule name. - - .. deprecated:: 1.0.0 - - Examples - -------- - get_offset('EOM') --> BMonthEnd(1) - """ - warnings.warn( - "get_offset is deprecated and will be removed in a future version, " - "use to_offset instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return _get_offset(name) - - # --------------------------------------------------------------------- # Period codes -def infer_freq(index, warn: bool = True) -> str | None: +def infer_freq(index) -> str | None: """ Infer the most likely frequency given the input index. @@ -133,8 +109,6 @@ def infer_freq(index, warn: bool = True) -> str | None: ---------- index : DatetimeIndex or TimedeltaIndex If passed a Series will use the values of the series (NOT THE INDEX). - warn : bool, default True - .. deprecated:: 1.5.0 Returns ------- @@ -186,7 +160,7 @@ def infer_freq(index, warn: bool = True) -> str | None: ) elif is_timedelta64_dtype(index.dtype): # Allow TimedeltaIndex and TimedeltaArray - inferer = _TimedeltaFrequencyInferer(index, warn=warn) + inferer = _TimedeltaFrequencyInferer(index) return inferer.get_freq() if isinstance(index, Index) and not isinstance(index, DatetimeIndex): @@ -199,7 +173,7 @@ def infer_freq(index, warn: bool = True) -> str | None: if not isinstance(index, DatetimeIndex): index = DatetimeIndex(index) - inferer = _FrequencyInferer(index, warn=warn) + inferer = _FrequencyInferer(index) return inferer.get_freq() @@ -208,7 +182,7 @@ class _FrequencyInferer: Not sure if I can avoid the state machine here """ - def __init__(self, index, warn: bool = True) -> None: + def __init__(self, index) -> None: self.index = index self.i8values = index.asi8 @@ -230,15 +204,6 @@ def __init__(self, index, warn: bool = True) -> None: if index.tz is not None: self.i8values = tz_convert_from_utc(self.i8values, index.tz) - if warn is not True: - warnings.warn( - "warn is deprecated (and never implemented) and " - "will be removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(), - ) - self.warn = warn - if len(index) < 3: raise ValueError("Need at least 3 dates to infer frequency") @@ -652,7 +617,6 @@ def _is_weekly(rule: str) -> bool: __all__ = [ "Day", - "get_offset", "get_period_alias", "infer_freq", "is_subperiod",