-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: lower/uppercase strings such as 'y', 'q', 'H', 'MIN', etc. denoting freqs/units for time series, period, and timedelta #56346
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
Changes from 3 commits
c7d82ec
614710b
458a9c1
e9c8af5
73f68f0
eea9b69
386eb57
5dcb918
25bfbef
eb418eb
943b898
435db76
3cc94d2
457ae96
3837b7f
f709557
7cd909f
8d1d6dd
6c24541
286b618
606d0c5
32993a9
dcf1994
5443b1e
7889c7d
00e80c0
0eb098e
b6074b1
530f056
f600538
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4554,29 +4554,7 @@ _lite_rule_alias = { | |
"ns": "ns", | ||
} | ||
|
||
_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", | ||
"ye", | ||
} | ||
_dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s"} | ||
|
||
|
||
INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" | ||
|
@@ -4595,7 +4573,8 @@ def _get_offset(name: str) -> BaseOffset: | |
-------- | ||
_get_offset('EOM') --> BMonthEnd(1) | ||
""" | ||
if name.lower() not in _dont_uppercase: | ||
name_orig = name | ||
if name not in _dont_uppercase: | ||
name = name.upper() | ||
name = _lite_rule_alias.get(name, name) | ||
name = _lite_rule_alias.get(name.lower(), name) | ||
|
@@ -4612,7 +4591,14 @@ def _get_offset(name: str) -> BaseOffset: | |
except (ValueError, TypeError, KeyError) as err: | ||
# bad prefix or suffix | ||
raise ValueError(INVALID_FREQ_ERR_MSG.format( | ||
f"{name}, failed to parse with error message: {repr(err)}") | ||
f"{name_orig}, failed to parse with error message: {repr(err)}") | ||
) | ||
if name != name_orig and name_orig != "d": | ||
warnings.warn( | ||
f"\'{name_orig}\' is deprecated and will be removed in a future " | ||
f"version, please use \'{name_orig.upper()}\' instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
# cache | ||
_offset_map[name] = offset | ||
|
@@ -4688,39 +4674,54 @@ cpdef to_offset(freq, bint is_period=False): | |
|
||
tups = zip(split[0::4], split[1::4], split[2::4]) | ||
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"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
name = c_OFFSET_DEPR_FREQSTR[name] | ||
if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR: | ||
if name.startswith("Y"): | ||
if is_period is False and name.upper() in c_OFFSET_DEPR_FREQSTR: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, little nitpick, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, |
||
if name == "m" and (n > 0 or stride == "-"): | ||
name = name | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is super-complicated, I can't understand it anymore would it work to just keep this part as it is, and at the beginning of if name not in _lite_rule_alias and (name.upper() in _lite_rule_alias):
warnings.warn(
f"\'{name}\' is deprecated and will be removed in a future "
f"version, please use \'{name.upper()}\' instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
elif name not in _lite_rule_alias and (name.lower() in _lite_rule_alias):
warnings.warn(
f"\'{name}\' is deprecated and will be removed in a future "
f"version, please use \'{name.lower()}\' instead.",
FutureWarning,
stacklevel=find_stack_level(),
) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the comment, I added it in
was for frequencies like |
||
warnings.warn( | ||
f"\'{name}\' is deprecated, please use " | ||
f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
name = c_OFFSET_DEPR_FREQSTR[name.upper()] | ||
if is_period is True and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: | ||
if name.upper().startswith("Y"): | ||
raise ValueError( | ||
f"for Period, please use \'Y{name[2:]}\' " | ||
f"for Period, please use \'Y{name.upper()[2:]}\' " | ||
f"instead of \'{name}\'" | ||
) | ||
if (name.startswith("B") or | ||
name.startswith("S") or name.startswith("C")): | ||
if (name.upper().startswith("B") or | ||
name.upper().startswith("S") or | ||
name.upper().startswith("C")): | ||
raise ValueError(INVALID_FREQ_ERR_MSG.format(name)) | ||
else: | ||
raise ValueError( | ||
f"for Period, please use " | ||
f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name)}\' " | ||
f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name.upper())}\' " | ||
f"instead of \'{name}\'" | ||
) | ||
elif is_period is True and name in c_OFFSET_DEPR_FREQSTR: | ||
if name.startswith("A"): | ||
elif is_period is True 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 \'{c_DEPR_ABBREVS.get(name)}\' " | ||
f"instead.", | ||
f"version, please use " | ||
f"\'{c_DEPR_ABBREVS.get(name.upper())}\' instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
name = c_OFFSET_DEPR_FREQSTR.get(name) | ||
if name == "m" and (n > 0 or stride == "-"): | ||
name = name | ||
else: | ||
if name.upper() != name: | ||
warnings.warn( | ||
f"\'{name}\' is deprecated and will be removed in " | ||
f"a future version, please use \'{name.upper()}\' " | ||
f"instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) | ||
|
||
if sep != "" and not sep.isspace(): | ||
raise ValueError("separator must be spaces") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry could you remind me why we're special-casing 'd' please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my mistake. I did this because I got failures in tests for
freq="d"
, e.g.pandas/tests/resample/test_base.py -k test_resample_empty_dtypes
pandas/tests/tslibs/test_to_offset.py -k test_to_offset_leading_plus
but I had to replace deprecated lowercase frequency
'd'
with the uppercase'D'
. Am I correct, we want to use for Day uppercase'D'
?I will remove the check
name_orig != "d"
and will correct tests.