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: warn parameter in infer_freq #45947

Merged
merged 2 commits into from
Feb 12, 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: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Other Deprecations
- Deprecated :meth:`Series.is_monotonic` and :meth:`Index.is_monotonic` in favor of :meth:`Series.is_monotonic_increasing` and :meth:`Index.is_monotonic_increasing` (:issue:`45422`, :issue:`21335`)
- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`)
- Deprecated the behavior of :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtype and incompatible fill value; in a future version this will cast to a common dtype (usually object) instead of raising, matching the behavior of other dtypes (:issue:`45746`)
-
- Deprecated the ``warn`` parameter in :func:`infer_freq` (:issue:`45947`)


.. ---------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/tseries/frequencies/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,8 @@ def test_ms_vs_capital_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)
11 changes: 9 additions & 2 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def get_offset(name: str) -> DateOffset:

def infer_freq(index, warn: bool = True) -> str | None:
"""
Infer the most likely frequency given the input index. If the frequency is
uncertain, a warning will be printed.
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 @@ -220,6 +220,13 @@ def __init__(self, index, warn: bool = True):
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=3,
)
self.warn = warn

if len(index) < 3:
Expand Down