Skip to content

BUG: renaming offsets quarterly frequencies with various fiscal year ends #55711

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 24 additions & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4616,7 +4616,28 @@ _lite_rule_alias = {
"ns": "ns",
}

_dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s", "me", "qe"}
_dont_uppercase = {
"h",
"bh",
"cbh",
"MS",
"ms",
"s",
"me",
"qe",
"qe-dec",
"qe-jan",
"qe-feb",
"qe-mar",
"qe-apr",
"qe-may",
"qe-jun",
"qe-jul",
"qe-aug",
"qe-sep",
"qe-oct",
"qe-nov",
}


INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}"
Expand All @@ -4635,6 +4656,8 @@ def _get_offset(name: str) -> BaseOffset:
--------
_get_offset('EOM') --> BMonthEnd(1)
"""
if name.upper() != name:
name = name.lower()
Copy link
Member

Choose a reason for hiding this comment

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

why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's necessary in order to catch frequencies like 'qe-MAr' with mix of lower/uppercase letters. Otherwise we should add all possible combinations to _dont_uppercase list.

Copy link
Member

Choose a reason for hiding this comment

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

ah I see, thanks!

Before this change:

In [4]: _get_offset('Qe-mAR')
Out[4]: <QuarterEnd: startingMonth=3>

After this change:

In [2]: _get_offset('Qe-mAR')
---------------------------------------------------------------------------
ValueError: Invalid frequency: qe-mar

Would it work to simplify and just do

-    if name.upper() != name:
-        name = name.lower()
-    if name not in _dont_uppercase:
+    if name.lower() not in _dont_uppercase:

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I simplified the condition. I just wasn't sure that the frequency like ‘QE-MAR’ should also pass this check.

It looks confusing: we take an uppercase string, then lowercase it and check if the string is in the _dont_uppercase list.

Copy link
Member

Choose a reason for hiding this comment

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

agree, but I think we want to get rid of _dont_uppercase completely anyway

if name not in _dont_uppercase:
name = name.upper()
name = _lite_rule_alias.get(name, name)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/resample/test_period_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_basic_downsample(self, simple_period_range_series):
"rule,expected_error_msg",
[
("y-dec", "<YearEnd: month=12>"),
("qe-mar", "<QuarterEnd: startingMonth=3>"),
("Q-MAR", "<QuarterEnd: startingMonth=3>"),
Copy link
Member

Choose a reason for hiding this comment

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

nice - this is a period, so indeed the period alias should be used

Copy link
Contributor Author

@natmokval natmokval Oct 27, 2023

Choose a reason for hiding this comment

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

yeah, sorry I missed it in PR #55553

("M", "<MonthEnd>"),
("w-thu", "<Week: weekday=3>"),
],
Expand Down