Skip to content

[WIP] Complete offset prefix mapping #20562

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

Closed
Closed
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
2 changes: 2 additions & 0 deletions doc/source/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,8 @@ frequencies. We will refer to these aliases as *offset aliases*.
"L, ms", "milliseconds"
"U, us", "microseconds"
"N", "nanoseconds"
"WOM, "x-th day of the y-th week of each month frequency"
"LWOM", "x-th day of the last week of each month frequency"

Combining Aliases
~~~~~~~~~~~~~~~~~
Expand Down
23 changes: 13 additions & 10 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,7 @@ class Easter(DateOffset):
the revised method which is valid in years
1583-4099.
"""
_prefix = 'EASTER'
_adjust_dst = True
_attributes = frozenset(['n', 'normalize'])

Expand Down Expand Up @@ -2451,23 +2452,30 @@ def generate_range(start=None, end=None, periods=None,


prefix_mapping = dict((offset._prefix, offset) for offset in [
YearBegin, # 'AS'
YearEnd, # 'A'
BYearBegin, # 'BAS'
BYearEnd, # 'BA'
YearBegin, # 'AS'
BusinessDay, # 'B'
BYearEnd, # 'BA'
BYearBegin, # 'BAS'
BusinessHour, # 'BH'
BusinessMonthBegin, # 'BMS'
BusinessMonthEnd, # 'BM'
BQuarterEnd, # 'BQ'
BQuarterBegin, # 'BQS'
BusinessHour, # 'BH'
CustomBusinessDay, # 'C'
CustomBusinessHour, # 'CBH'
CustomBusinessMonthEnd, # 'CBM'
CustomBusinessMonthBegin, # 'CBMS'
CustomBusinessHour, # 'CBH'
Copy link
Member

Choose a reason for hiding this comment

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

What’s the logic behind reordering these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were ordered alphabetically by alias. The reason was human readability.

This PR is out-of-date. I did more work on this here fix_lwom, but test were failing because of imo unrelated reasons, and I did not add it to this PR.

I will rebase and try again. Hopefully, this PR is then in shape to be merged.

Day, # 'D'
Easter, # 'EASTER'
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need Easter in this list

Hour, # 'H'
Milli, # 'L'
LastWeekOfMonth, # 'LWOM'
MonthEnd, # 'M'
MonthBegin, # 'MS'
Nano, # 'N'
FY5253, # 'RE'
FY5253Quarter, # 'REQ'
SemiMonthEnd, # 'SM'
SemiMonthBegin, # 'SMS'
Week, # 'W'
Expand All @@ -2476,10 +2484,5 @@ def generate_range(start=None, end=None, periods=None,
Micro, # 'U'
QuarterEnd, # 'Q'
QuarterBegin, # 'QS'
Milli, # 'L'
Hour, # 'H'
Day, # 'D'
WeekOfMonth, # 'WOM'
FY5253,
FY5253Quarter,
])