Skip to content
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

DEPR: Remove get_offset, infer_freq warn param #49314

Merged
merged 1 commit into from
Oct 26, 2022
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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,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`)
Expand Down
12 changes: 4 additions & 8 deletions pandas/tests/tseries/frequencies/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
],
)
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 0 additions & 44 deletions pandas/tests/tseries/offsets/test_fiscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 4 additions & 40 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import warnings

import numpy as np

from pandas._libs.algos import unique_deltas
Expand All @@ -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,
Expand Down Expand Up @@ -102,39 +97,18 @@ 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.

Parameters
----------
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
-------
Expand Down Expand Up @@ -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):
Expand All @@ -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()


Expand All @@ -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

Expand All @@ -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")

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

__all__ = [
"Day",
"get_offset",
"get_period_alias",
"infer_freq",
"is_subperiod",
Expand Down