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: remove deprecated freqs/abbrevs 'A', 'A-DEC', 'A-JAN', etc. #57699

Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 0 additions & 27 deletions pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,6 @@ cdef dict c_OFFSET_DEPR_FREQSTR = {
"Y-SEP": "YE-SEP",
"Y-OCT": "YE-OCT",
"Y-NOV": "YE-NOV",
"A": "YE",
"A-DEC": "YE-DEC",
"A-JAN": "YE-JAN",
"A-FEB": "YE-FEB",
"A-MAR": "YE-MAR",
"A-APR": "YE-APR",
"A-MAY": "YE-MAY",
"A-JUN": "YE-JUN",
"A-JUL": "YE-JUL",
"A-AUG": "YE-AUG",
"A-SEP": "YE-SEP",
"A-OCT": "YE-OCT",
"A-NOV": "YE-NOV",
"BY": "BYE",
"BY-DEC": "BYE-DEC",
"BY-JAN": "BYE-JAN",
Expand Down Expand Up @@ -336,20 +323,6 @@ cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR = {

# Map deprecated resolution abbreviations to correct resolution abbreviations
cdef dict c_DEPR_ABBREVS = {
"A": "Y",
"a": "Y",
"A-DEC": "Y-DEC",
"A-JAN": "Y-JAN",
"A-FEB": "Y-FEB",
"A-MAR": "Y-MAR",
"A-APR": "Y-APR",
"A-MAY": "Y-MAY",
"A-JUN": "Y-JUN",
"A-JUL": "Y-JUL",
"A-AUG": "Y-AUG",
"A-SEP": "Y-SEP",
"A-OCT": "Y-OCT",
"A-NOV": "Y-NOV",
"BA": "BY",
"BA-DEC": "BY-DEC",
"BA-JAN": "BY-JAN",
Expand Down
8 changes: 0 additions & 8 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4885,14 +4885,6 @@ cpdef to_offset(freq, bint is_period=False):
f"instead of \'{name}\'"
)
elif is_period and name.upper() in c_OFFSET_DEPR_FREQSTR:
if name.upper().startswith("A"):
warnings.warn(
f"\'{name}\' is deprecated and will be removed in a future "
f"version, please use "
f"\'{c_DEPR_ABBREVS.get(name.upper())}\' instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
if name.upper() != name:
warnings.warn(
f"\'{name}\' is deprecated and will be removed in "
Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,8 @@ def test_iter_zoneinfo_fold(self, tz):
("2QE-SEP", "2Q-SEP"),
("1YE", "1Y"),
("2YE-MAR", "2Y-MAR"),
("1YE", "1A"),
("2YE-MAR", "2A-MAR"),
("2ME", "2m"),
("2QE-SEP", "2q-sep"),
("2YE-MAR", "2a-mar"),
("2YE", "2y"),
],
)
Expand Down Expand Up @@ -826,6 +823,13 @@ def test_date_range_lowercase_frequency_deprecated(self, freq_depr):
result = pd.date_range("1/1/2000", periods=4, freq=freq_depr)
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize("freq", ["1A", "2A-MAR", "2a-mar"])
def test_date_range_frequency_A_raises(self, freq):
msg = f"Invalid frequency: {freq}"

with pytest.raises(ValueError, match=msg):
pd.date_range("1/1/2000", periods=4, freq=freq)


def test_factorize_sort_without_freq():
dta = DatetimeArray._from_sequence([0, 2, 1], dtype="M8[ns]")
Expand Down
18 changes: 16 additions & 2 deletions pandas/tests/frame/methods/test_asfreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ def test_asfreq_2ME(self, freq, freq_half):
("2BQE-SEP", "2BQ-SEP"),
("1YE", "1Y"),
("2YE-MAR", "2Y-MAR"),
("1YE", "1A"),
("2YE-MAR", "2A-MAR"),
("2BYE-MAR", "2BA-MAR"),
],
)
Expand Down Expand Up @@ -283,3 +281,19 @@ def test_asfreq_unsupported_freq(self, freq, error_msg):

with pytest.raises(ValueError, match=error_msg):
df.asfreq(freq=freq)

@pytest.mark.parametrize(
"freq, freq_depr",
[
("1YE", "1A"),
("2YE-MAR", "2A-MAR"),
],
)
def test_asfreq_frequency_A_raisees(self, freq, freq_depr):
msg = f"Invalid frequency: {freq_depr[1:]}"

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)})

with pytest.raises(ValueError, match=msg):
df.asfreq(freq=freq_depr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear to me what you're doing with freq in this test - I think index can just be instatiated with 'YE' in both cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, in the first case we get df.index.freqstr = YE-DEC, and in second case df.index.freqstr =YE-MAR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right, it's sufficient to check only freq="A". I simplified the test and added a note to v3.0.0.
Could you please take a look at my changes?

4 changes: 1 addition & 3 deletions pandas/tests/indexes/datetimes/methods/test_to_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ def test_dti_to_period_2monthish(self, freq_offset, freq_period):
("2QE-SEP", "2Q-SEP"),
("1YE", "1Y"),
("2YE-MAR", "2Y-MAR"),
("1YE", "1A"),
("2YE-MAR", "2A-MAR"),
],
)
def test_to_period_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
def test_to_period_frequency_M_Q_Y_deprecated(self, freq, freq_depr):
# GH#9586
msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
f"in a future version, please use '{freq[1:]}' instead."
Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,11 @@ def test_frequencies_H_T_S_L_U_N_deprecated(self, freq, freq_depr):
@pytest.mark.parametrize(
"freq,freq_depr",
[
("200YE", "200A"),
("YE", "Y"),
("2YE-MAY", "2A-MAY"),
("YE-MAY", "Y-MAY"),
],
)
def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr):
def test_frequencies_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]
Expand Down Expand Up @@ -836,6 +834,14 @@ def test_date_range_bday(self):
assert idx[0] == sdate + 0 * offsets.BDay()
assert idx.freq == "B"

@pytest.mark.parametrize("freq", ["200A", "2A-MAY"])
def test_frequency_A_raises(self, freq):
freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1]
msg = f"Invalid frequency: {freq_msg}"

with pytest.raises(ValueError, match=msg):
date_range("1/1/2000", periods=2, freq=freq)


class TestDateRangeTZ:
"""Tests for date_range with timezones"""
Expand Down
24 changes: 7 additions & 17 deletions pandas/tests/indexes/period/test_period_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,6 @@ def test_constructor_U(self):
with pytest.raises(ValueError, match="Invalid frequency: X"):
period_range("2007-1-1", periods=500, freq="X")

@pytest.mark.parametrize(
"freq,freq_depr",
[
("2Y", "2A"),
("2Y", "2a"),
("2Y-AUG", "2A-AUG"),
("2Y-AUG", "2A-aug"),
],
)
def test_a_deprecated_from_time_series(self, freq, freq_depr):
# GH#52536
msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
f"future version. Please use '{freq[1:]}' instead."

with tm.assert_produces_warning(FutureWarning, match=msg):
period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009")

@pytest.mark.parametrize("freq_depr", ["2H", "2MIN", "2S", "2US", "2NS"])
def test_uppercase_freq_deprecated_from_time_series(self, freq_depr):
# GH#52536, GH#54939
Expand All @@ -239,3 +222,10 @@ def test_lowercase_freq_deprecated_from_time_series(self, freq_depr):

with tm.assert_produces_warning(FutureWarning, match=msg):
period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009")

@pytest.mark.parametrize("freq", ["2A", "2a", "2A-AUG", "2A-aug"])
def test_A_raises_from_time_series(self, freq):
msg = f"Invalid frequency: {freq}"

with pytest.raises(ValueError, match=msg):
period_range(freq=freq, start="1/1/2001", end="12/1/2009")
13 changes: 10 additions & 3 deletions pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,11 +2047,9 @@ def test_resample_empty_series_with_tz():
("2QE-SEP", "2Q-SEP"),
("1YE", "1Y"),
("2YE-MAR", "2Y-MAR"),
("1YE", "1A"),
("2YE-MAR", "2A-MAR"),
],
)
def test_resample_M_Q_Y_A_deprecated(freq, freq_depr):
def test_resample_M_Q_Y_deprecated(freq, freq_depr):
# GH#9586
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
f"in a future version, please use '{freq[1:]}' instead."
Expand Down Expand Up @@ -2174,3 +2172,12 @@ def test_arrow_timestamp_resample(tz):
expected = Series(np.arange(5, dtype=np.float64), index=idx)
result = expected.resample("1D").mean()
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("freq", ["1A", "2A-MAR"])
def test_resample_A_raises(freq):
msg = f"Invalid frequency: {freq[1:]}"

s = Series(range(10), index=date_range("20130101", freq="d", periods=10))
with pytest.raises(ValueError, match=msg):
s.resample(freq).mean()
4 changes: 2 additions & 2 deletions pandas/tests/tslibs/test_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def test_get_attrname_from_abbrev(freqstr, expected):
assert reso.attrname == expected


@pytest.mark.parametrize("freq", ["A", "H", "T", "S", "L", "U", "N"])
def test_units_A_H_T_S_L_U_N_deprecated_from_attrname_to_abbrevs(freq):
@pytest.mark.parametrize("freq", ["H", "T", "S", "L", "U", "N"])
def test_units_H_T_S_L_U_N_deprecated_from_attrname_to_abbrevs(freq):
# GH#52536
msg = f"'{freq}' is deprecated and will be removed in a future version."

Expand Down