diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 4298809b0f2e4..a35ca589065d8 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -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`) .. --------------------------------------------------------------------------- diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index f8fde000354e0..704028a7827cd 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -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) diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 415af96a29aa3..3807189f7681b 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -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 ------- @@ -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: