Skip to content

Commit

Permalink
DEPR: warn parameter in infer_freq (pandas-dev#45947)
Browse files Browse the repository at this point in the history
* DEPR: warn parameter in infer_freq

* Add issue number
  • Loading branch information
mroeschke authored and phofl committed Feb 14, 2022
1 parent 5180d32 commit e53031b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit e53031b

Please sign in to comment.