From f571ccef75aed37789e1d14cb3a54089c8ca3771 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva <91160475+natmokval@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:46:40 +0100 Subject: [PATCH] ENH: unify warning message in to_offset() (#56417) * ENH: unify warning message for deprecated freqs * correct warning message for deprecated abbreviations --- pandas/_libs/tslibs/offsets.pyx | 8 ++++---- pandas/tests/arrays/test_datetimes.py | 3 ++- pandas/tests/frame/methods/test_asfreq.py | 3 ++- .../indexes/datetimes/methods/test_to_period.py | 6 ++++-- pandas/tests/indexes/datetimes/test_date_range.py | 14 ++++++++++---- pandas/tests/indexes/datetimes/test_datetime.py | 3 ++- pandas/tests/resample/test_datetime_index.py | 6 ++++-- 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 3ea8fbf69b28b..b893939969c68 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4786,7 +4786,8 @@ cpdef to_offset(freq, bint is_period=False): for n, (sep, stride, name) in enumerate(tups): if is_period is False and name in c_OFFSET_DEPR_FREQSTR: warnings.warn( - f"\'{name}\' is deprecated, please use " + f"\'{name}\' is deprecated and will be removed " + f"in a future version, please use " f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.", FutureWarning, stacklevel=find_stack_level(), @@ -4829,9 +4830,8 @@ cpdef to_offset(freq, bint is_period=False): if prefix in c_DEPR_ABBREVS: warnings.warn( f"\'{prefix}\' is deprecated and will be removed " - f"in a future version. Please use " - f"\'{c_DEPR_ABBREVS.get(prefix)}\' " - f"instead of \'{prefix}\'.", + f"in a future version, please use " + f"\'{c_DEPR_ABBREVS.get(prefix)}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 13736700c1a6f..db86f62a10484 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -774,7 +774,8 @@ def test_iter_zoneinfo_fold(self, tz): ) def test_date_range_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): # GH#9586, GH#54275 - depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." expected = pd.date_range("1/1/2000", periods=4, freq=freq) with tm.assert_produces_warning(FutureWarning, match=depr_msg): diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index 6926917a09602..ef72ca1ac86b9 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -252,7 +252,8 @@ def test_asfreq_2ME(self, freq, freq_half): ) def test_asfreq_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): # GH#9586, #55978 - depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." index = date_range("1/1/2000", periods=4, freq=f"{freq[1:]}") df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)}) diff --git a/pandas/tests/indexes/datetimes/methods/test_to_period.py b/pandas/tests/indexes/datetimes/methods/test_to_period.py index 2c68ddd3d3d15..42a3f3b0f7b42 100644 --- a/pandas/tests/indexes/datetimes/methods/test_to_period.py +++ b/pandas/tests/indexes/datetimes/methods/test_to_period.py @@ -103,7 +103,8 @@ def test_dti_to_period_2monthish(self, freq_offset, freq_period): ) def test_to_period_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): # GH#9586 - msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." rng = date_range("01-Jan-2012", periods=8, freq=freq) prng = rng.to_period() @@ -119,7 +120,8 @@ def test_to_period_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): ) def test_to_period_frequency_BQ_BY_deprecated(self, freq, freq_depr): # GH#9586 - msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." rng = date_range("01-Jan-2012", periods=8, freq=freq) prng = rng.to_period() diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index dfad4d7ad01ea..44dd64e162413 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -157,7 +157,8 @@ def test_date_range_fractional_period(self): ) def test_date_range_frequency_M_SM_BQ_BY_deprecated(self, freq, freq_depr): # GH#52064 - depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." expected = date_range("1/1/2000", periods=4, freq=freq) with tm.assert_produces_warning(FutureWarning, match=depr_msg): @@ -788,8 +789,12 @@ def test_freq_dateoffset_with_relateivedelta_nanos(self): ) def test_frequencies_H_T_S_L_U_N_deprecated(self, freq, freq_depr): # GH#52536 - freq_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1] - msg = f"'{freq_msg}' is deprecated and will be removed in a future version." + freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1] + freq_depr_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1] + msg = ( + f"'{freq_depr_msg}' is deprecated and will be removed in a future version, " + ) + f"please use '{freq_msg}' instead" expected = date_range("1/1/2000", periods=2, freq=freq) with tm.assert_produces_warning(FutureWarning, match=msg): @@ -809,7 +814,8 @@ def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr): # GH#9586, GH#54275 freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1] freq_depr_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1] - msg = f"'{freq_depr_msg}' is deprecated, please use '{freq_msg}' instead." + msg = f"'{freq_depr_msg}' is deprecated and will be removed " + f"in a future version, please use '{freq_msg}' instead." expected = date_range("1/1/2000", periods=2, freq=freq) with tm.assert_produces_warning(FutureWarning, match=msg): diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index d2d627c27312a..f7fc64d4b0163 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -202,7 +202,8 @@ def test_AS_BAS_deprecated(self, freq_depr, expected_values, expected_freq): ) def test_BM_BQ_BY_deprecated(self, freq, expected_values, freq_depr): # GH#52064 - msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." with tm.assert_produces_warning(FutureWarning, match=msg): expected = date_range(start="2016-02-21", end="2016-08-21", freq=freq_depr) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 760ed35bab678..a9701b7ecd607 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -2102,7 +2102,8 @@ def test_resample_empty_series_with_tz(): ) def test_resample_M_Q_Y_A_deprecated(freq, freq_depr): # GH#9586 - depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) expected = s.resample(freq).mean() @@ -2121,7 +2122,8 @@ def test_resample_M_Q_Y_A_deprecated(freq, freq_depr): ) def test_resample_BM_BQ_deprecated(freq, freq_depr): # GH#52064 - depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " + f"in a future version, please use '{freq[1:]}' instead." s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) expected = s.resample(freq).mean()