Skip to content

Commit 932ee2f

Browse files
mroeschkenoatamir
authored andcommitted
DEPR: Remove get_offset, infer_freq warn param (pandas-dev#49314)
1 parent 499fef8 commit 932ee2f

File tree

4 files changed

+10
-92
lines changed

4 files changed

+10
-92
lines changed

doc/source/whatsnew/v2.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ Removal of prior version deprecations/changes
219219
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
220220
- Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`)
221221
- Disallow passing abbreviations for ``orient`` in :meth:`DataFrame.to_dict` (:issue:`32516`)
222+
- Removed ``get_offset`` in favor of :func:`to_offset` (:issue:`30340`)
223+
- Removed the ``warn`` keyword in :func:`infer_freq` (:issue:`45947`)
222224
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
223225
- Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`)
224226
- Removed the ``pandas.datetime`` submodule (:issue:`30489`)

pandas/tests/tseries/frequencies/test_inference.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
DAYS,
1111
MONTHS,
1212
)
13+
from pandas._libs.tslibs.offsets import _get_offset
1314
from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG
1415
from pandas.compat import is_platform_windows
1516

@@ -447,7 +448,7 @@ def test_series_datetime_index(freq):
447448
@pytest.mark.parametrize(
448449
"offset_func",
449450
[
450-
frequencies._get_offset,
451+
_get_offset,
451452
lambda freq: date_range("2011-01-01", periods=5, freq=freq),
452453
],
453454
)
@@ -507,18 +508,13 @@ def test_legacy_offset_warnings(offset_func, freq):
507508

508509

509510
def test_ms_vs_capital_ms():
510-
left = frequencies._get_offset("ms")
511-
right = frequencies._get_offset("MS")
511+
left = _get_offset("ms")
512+
right = _get_offset("MS")
512513

513514
assert left == offsets.Milli()
514515
assert right == offsets.MonthBegin()
515516

516517

517-
def test_infer_freq_warn_deprecated():
518-
with tm.assert_produces_warning(FutureWarning):
519-
frequencies.infer_freq(date_range(2022, periods=3), warn=False)
520-
521-
522518
def test_infer_freq_non_nano():
523519
arr = np.arange(10).astype(np.int64).view("M8[s]")
524520
dta = DatetimeArray._simple_new(arr, dtype=arr.dtype)

pandas/tests/tseries/offsets/test_fiscal.py

-44
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
from dateutil.relativedelta import relativedelta
77
import pytest
88

9-
from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG
10-
119
from pandas import Timestamp
12-
import pandas._testing as tm
1310
from pandas.tests.tseries.offsets.common import (
1411
WeekDay,
1512
assert_is_on_offset,
1613
assert_offset_equal,
1714
)
1815

19-
from pandas.tseries.frequencies import get_offset
2016
from pandas.tseries.offsets import (
2117
FY5253,
2218
FY5253Quarter,
@@ -54,46 +50,6 @@ def test_get_offset_name():
5450
)
5551

5652

57-
def test_get_offset():
58-
with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG):
59-
with tm.assert_produces_warning(FutureWarning):
60-
get_offset("gibberish")
61-
with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG):
62-
with tm.assert_produces_warning(FutureWarning):
63-
get_offset("QS-JAN-B")
64-
65-
pairs = [
66-
("RE-N-DEC-MON", makeFY5253NearestEndMonth(weekday=0, startingMonth=12)),
67-
("RE-L-DEC-TUE", makeFY5253LastOfMonth(weekday=1, startingMonth=12)),
68-
(
69-
"REQ-L-MAR-TUE-4",
70-
makeFY5253LastOfMonthQuarter(
71-
weekday=1, startingMonth=3, qtr_with_extra_week=4
72-
),
73-
),
74-
(
75-
"REQ-L-DEC-MON-3",
76-
makeFY5253LastOfMonthQuarter(
77-
weekday=0, startingMonth=12, qtr_with_extra_week=3
78-
),
79-
),
80-
(
81-
"REQ-N-DEC-MON-3",
82-
makeFY5253NearestEndMonthQuarter(
83-
weekday=0, startingMonth=12, qtr_with_extra_week=3
84-
),
85-
),
86-
]
87-
88-
for name, expected in pairs:
89-
with tm.assert_produces_warning(FutureWarning):
90-
offset = get_offset(name)
91-
assert offset == expected, (
92-
f"Expected {repr(name)} to yield {repr(expected)} "
93-
f"(actual: {repr(offset)})"
94-
)
95-
96-
9753
class TestFY5253LastOfMonth:
9854
offset_lom_sat_aug = makeFY5253LastOfMonth(1, startingMonth=8, weekday=WeekDay.SAT)
9955
offset_lom_sat_sep = makeFY5253LastOfMonth(1, startingMonth=9, weekday=WeekDay.SAT)

pandas/tseries/frequencies.py

+4-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import warnings
4-
53
import numpy as np
64

75
from pandas._libs.algos import unique_deltas
@@ -23,16 +21,13 @@
2321
month_position_check,
2422
)
2523
from pandas._libs.tslibs.offsets import (
26-
BaseOffset,
2724
DateOffset,
2825
Day,
29-
_get_offset,
3026
to_offset,
3127
)
3228
from pandas._libs.tslibs.parsing import get_rule_month
3329
from pandas._typing import npt
3430
from pandas.util._decorators import cache_readonly
35-
from pandas.util._exceptions import find_stack_level
3631

3732
from pandas.core.dtypes.common import (
3833
is_datetime64_dtype,
@@ -102,39 +97,18 @@ def get_period_alias(offset_str: str) -> str | None:
10297
return _offset_to_period_map.get(offset_str, None)
10398

10499

105-
def get_offset(name: str) -> BaseOffset:
106-
"""
107-
Return DateOffset object associated with rule name.
108-
109-
.. deprecated:: 1.0.0
110-
111-
Examples
112-
--------
113-
get_offset('EOM') --> BMonthEnd(1)
114-
"""
115-
warnings.warn(
116-
"get_offset is deprecated and will be removed in a future version, "
117-
"use to_offset instead.",
118-
FutureWarning,
119-
stacklevel=find_stack_level(),
120-
)
121-
return _get_offset(name)
122-
123-
124100
# ---------------------------------------------------------------------
125101
# Period codes
126102

127103

128-
def infer_freq(index, warn: bool = True) -> str | None:
104+
def infer_freq(index) -> str | None:
129105
"""
130106
Infer the most likely frequency given the input index.
131107
132108
Parameters
133109
----------
134110
index : DatetimeIndex or TimedeltaIndex
135111
If passed a Series will use the values of the series (NOT THE INDEX).
136-
warn : bool, default True
137-
.. deprecated:: 1.5.0
138112
139113
Returns
140114
-------
@@ -186,7 +160,7 @@ def infer_freq(index, warn: bool = True) -> str | None:
186160
)
187161
elif is_timedelta64_dtype(index.dtype):
188162
# Allow TimedeltaIndex and TimedeltaArray
189-
inferer = _TimedeltaFrequencyInferer(index, warn=warn)
163+
inferer = _TimedeltaFrequencyInferer(index)
190164
return inferer.get_freq()
191165

192166
if isinstance(index, Index) and not isinstance(index, DatetimeIndex):
@@ -199,7 +173,7 @@ def infer_freq(index, warn: bool = True) -> str | None:
199173
if not isinstance(index, DatetimeIndex):
200174
index = DatetimeIndex(index)
201175

202-
inferer = _FrequencyInferer(index, warn=warn)
176+
inferer = _FrequencyInferer(index)
203177
return inferer.get_freq()
204178

205179

@@ -208,7 +182,7 @@ class _FrequencyInferer:
208182
Not sure if I can avoid the state machine here
209183
"""
210184

211-
def __init__(self, index, warn: bool = True) -> None:
185+
def __init__(self, index) -> None:
212186
self.index = index
213187
self.i8values = index.asi8
214188

@@ -230,15 +204,6 @@ def __init__(self, index, warn: bool = True) -> None:
230204
if index.tz is not None:
231205
self.i8values = tz_convert_from_utc(self.i8values, index.tz)
232206

233-
if warn is not True:
234-
warnings.warn(
235-
"warn is deprecated (and never implemented) and "
236-
"will be removed in a future version.",
237-
FutureWarning,
238-
stacklevel=find_stack_level(),
239-
)
240-
self.warn = warn
241-
242207
if len(index) < 3:
243208
raise ValueError("Need at least 3 dates to infer frequency")
244209

@@ -652,7 +617,6 @@ def _is_weekly(rule: str) -> bool:
652617

653618
__all__ = [
654619
"Day",
655-
"get_offset",
656620
"get_period_alias",
657621
"infer_freq",
658622
"is_subperiod",

0 commit comments

Comments
 (0)