Skip to content

Commit 5bf346c

Browse files
authored
DEPR: warn parameter in infer_freq (#45947)
* DEPR: warn parameter in infer_freq * Add issue number
1 parent 34dd0ba commit 5bf346c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

doc/source/whatsnew/v1.5.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Other Deprecations
240240
- 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`)
241241
- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`)
242242
- 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`)
243-
-
243+
- Deprecated the ``warn`` parameter in :func:`infer_freq` (:issue:`45947`)
244244

245245

246246
.. ---------------------------------------------------------------------------

pandas/tests/tseries/frequencies/test_inference.py

+5
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,8 @@ def test_ms_vs_capital_ms():
502502

503503
assert left == offsets.Milli()
504504
assert right == offsets.MonthBegin()
505+
506+
507+
def test_infer_freq_warn_deprecated():
508+
with tm.assert_produces_warning(FutureWarning):
509+
frequencies.infer_freq(date_range(2022, periods=3), warn=False)

pandas/tseries/frequencies.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ def get_offset(name: str) -> DateOffset:
128128

129129
def infer_freq(index, warn: bool = True) -> str | None:
130130
"""
131-
Infer the most likely frequency given the input index. If the frequency is
132-
uncertain, a warning will be printed.
131+
Infer the most likely frequency given the input index.
133132
134133
Parameters
135134
----------
136135
index : DatetimeIndex or TimedeltaIndex
137136
If passed a Series will use the values of the series (NOT THE INDEX).
138137
warn : bool, default True
138+
.. deprecated:: 1.5.0
139139
140140
Returns
141141
-------
@@ -220,6 +220,13 @@ def __init__(self, index, warn: bool = True):
220220
self.i8values, index.tz
221221
)
222222

223+
if warn is not True:
224+
warnings.warn(
225+
"warn is deprecated (and never implemented) and "
226+
"will be removed in a future version.",
227+
FutureWarning,
228+
stacklevel=3,
229+
)
223230
self.warn = warn
224231

225232
if len(index) < 3:

0 commit comments

Comments
 (0)