Skip to content

Commit 1f55e91

Browse files
agrabosojreback
authored andcommitted
DEPR: Remove legacy offsets
Follow-up to #13590. Remove legacy offset aliases that remained in `pandas/tseries/frequencies.py`: `_period_alias_dictionary()` and `_period_alias_dict`. Author: agraboso <[email protected]> Closes #13868 from agraboso/follow-13590 and squashes the following commits: 25d932d [agraboso] DEPR: Remove legacy offsets
1 parent 299fb75 commit 1f55e91

File tree

4 files changed

+9
-115
lines changed

4 files changed

+9
-115
lines changed

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ Removal of prior version deprecations/changes
701701
- ``Series.to_csv`` has dropped the ``nanRep`` parameter in favor of ``na_rep`` (:issue:`13804`)
702702
- ``Series.xs``, ``DataFrame.xs``, ``Panel.xs``, ``Panel.major_xs``, and ``Panel.minor_xs`` have dropped the ``copy`` parameter (:issue:`13781`)
703703
- ``str.split`` has dropped the ``return_type`` parameter in favor of ``expand`` (:issue:`13701`)
704-
- Removal of the legacy time rules (offset aliases), deprecated since 0.17.0 (this has been alias since 0.8.0) (:issue:`13590`)
704+
- Removal of the legacy time rules (offset aliases), deprecated since 0.17.0 (this has been alias since 0.8.0) (:issue:`13590`, :issue:`13868`)
705705

706706
Previous Behavior:
707707

pandas/src/period.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,7 @@ cdef class _Period(object):
681681
@classmethod
682682
def _maybe_convert_freq(cls, object freq):
683683

684-
if isinstance(freq, compat.string_types):
685-
freq = freq.upper()
686-
freq = frequencies._period_alias_dict.get(freq, freq)
687-
elif isinstance(freq, (int, tuple)):
684+
if isinstance(freq, (int, tuple)):
688685
code, stride = frequencies.get_freq_code(freq)
689686
freq = frequencies._get_freq_str(code, stride)
690687

pandas/tseries/frequencies.py

-107
Original file line numberDiff line numberDiff line change
@@ -620,113 +620,6 @@ def get_standard_freq(freq):
620620
})
621621

622622

623-
def _period_alias_dictionary():
624-
"""
625-
Build freq alias dictionary to support freqs from original c_dates.c file
626-
of the scikits.timeseries library.
627-
"""
628-
alias_dict = {}
629-
630-
M_aliases = ["M", "MTH", "MONTH", "MONTHLY"]
631-
B_aliases = ["B", "BUS", "BUSINESS", "BUSINESSLY", "WEEKDAY"]
632-
D_aliases = ["D", "DAY", "DLY", "DAILY"]
633-
H_aliases = ["H", "HR", "HOUR", "HRLY", "HOURLY"]
634-
T_aliases = ["T", "MIN", "MINUTE", "MINUTELY"]
635-
S_aliases = ["S", "SEC", "SECOND", "SECONDLY"]
636-
L_aliases = ["L", "ms", "MILLISECOND", "MILLISECONDLY"]
637-
U_aliases = ["U", "US", "MICROSECOND", "MICROSECONDLY"]
638-
N_aliases = ["N", "NS", "NANOSECOND", "NANOSECONDLY"]
639-
640-
for k in M_aliases:
641-
alias_dict[k] = 'M'
642-
643-
for k in B_aliases:
644-
alias_dict[k] = 'B'
645-
646-
for k in D_aliases:
647-
alias_dict[k] = 'D'
648-
649-
for k in H_aliases:
650-
alias_dict[k] = 'H'
651-
652-
for k in T_aliases:
653-
alias_dict[k] = 'T'
654-
655-
for k in S_aliases:
656-
alias_dict[k] = 'S'
657-
658-
for k in L_aliases:
659-
alias_dict[k] = 'L'
660-
661-
for k in U_aliases:
662-
alias_dict[k] = 'U'
663-
664-
for k in N_aliases:
665-
alias_dict[k] = 'N'
666-
667-
A_prefixes = ["A", "Y", "ANN", "ANNUAL", "ANNUALLY", "YR", "YEAR",
668-
"YEARLY"]
669-
670-
Q_prefixes = ["Q", "QTR", "QUARTER", "QUARTERLY", "Q-E",
671-
"QTR-E", "QUARTER-E", "QUARTERLY-E"]
672-
673-
month_names = [
674-
["DEC", "DECEMBER"],
675-
["JAN", "JANUARY"],
676-
["FEB", "FEBRUARY"],
677-
["MAR", "MARCH"],
678-
["APR", "APRIL"],
679-
["MAY", "MAY"],
680-
["JUN", "JUNE"],
681-
["JUL", "JULY"],
682-
["AUG", "AUGUST"],
683-
["SEP", "SEPTEMBER"],
684-
["OCT", "OCTOBER"],
685-
["NOV", "NOVEMBER"]]
686-
687-
seps = ["@", "-"]
688-
689-
for k in A_prefixes:
690-
alias_dict[k] = 'A'
691-
for m_tup in month_names:
692-
for sep in seps:
693-
m1, m2 = m_tup
694-
alias_dict[k + sep + m1] = 'A-' + m1
695-
alias_dict[k + sep + m2] = 'A-' + m1
696-
697-
for k in Q_prefixes:
698-
alias_dict[k] = 'Q'
699-
for m_tup in month_names:
700-
for sep in seps:
701-
m1, m2 = m_tup
702-
alias_dict[k + sep + m1] = 'Q-' + m1
703-
alias_dict[k + sep + m2] = 'Q-' + m1
704-
705-
W_prefixes = ["W", "WK", "WEEK", "WEEKLY"]
706-
707-
day_names = [
708-
["SUN", "SUNDAY"],
709-
["MON", "MONDAY"],
710-
["TUE", "TUESDAY"],
711-
["WED", "WEDNESDAY"],
712-
["THU", "THURSDAY"],
713-
["FRI", "FRIDAY"],
714-
["SAT", "SATURDAY"]]
715-
716-
for k in W_prefixes:
717-
alias_dict[k] = 'W'
718-
for d_tup in day_names:
719-
for sep in ["@", "-"]:
720-
d1, d2 = d_tup
721-
alias_dict[k + sep + d1] = 'W-' + d1
722-
alias_dict[k + sep + d2] = 'W-' + d1
723-
724-
return alias_dict
725-
726-
727-
_period_alias_dict = _period_alias_dictionary()
728-
729-
730623
def _period_str_to_code(freqstr):
731624
freqstr = _lite_rule_alias.get(freqstr, freqstr)
732625

pandas/tseries/tests/test_period.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,14 @@ def test_period_deprecated_freq(self):
457457
for freq in freqs:
458458
with self.assertRaisesRegexp(ValueError, msg):
459459
Period('2016-03-01 09:00', freq=freq)
460+
with self.assertRaisesRegexp(ValueError, msg):
461+
Period(ordinal=1, freq=freq)
460462

461-
# check supported freq-aliases still works
462-
p = Period('2016-03-01 09:00', freq=exp)
463-
tm.assertIsInstance(p, Period)
463+
# check supported freq-aliases still works
464+
p1 = Period('2016-03-01 09:00', freq=exp)
465+
p2 = Period(ordinal=1, freq=exp)
466+
tm.assertIsInstance(p1, Period)
467+
tm.assertIsInstance(p2, Period)
464468

465469
def test_hash(self):
466470
self.assertEqual(hash(Period('2011-01', freq='M')),

0 commit comments

Comments
 (0)