-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: enforced the deprecation of strings 'H', 'BH', 'CBH' in favor of 'h', 'bh', 'cbh' #59143
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
CLN: enforced the deprecation of strings 'H', 'BH', 'CBH' in favor of 'h', 'bh', 'cbh' #59143
Conversation
freq="cbh", | ||
) | ||
@pytest.mark.parametrize("freq", ["2H", "2BH", "2S"]) | ||
def test_CBH_deprecated(self, freq): |
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.
def test_CBH_deprecated(self, freq): | |
def test_CBH_raises(self, freq): |
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.
Thanks @mroeschke for reviewing this PR. I changed the name for the test.
pandas/_libs/tslibs/dtypes.pyx
Outdated
@@ -362,6 +359,8 @@ cdef dict c_PERIOD_AND_OFFSET_DEPR_FREQSTR = { | |||
"MIN": "min", | |||
} | |||
|
|||
INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" |
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.
INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" | |
cdef str INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" |
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.
done
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.
I think CI failures are unrelated to my changes.
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.
thanks for your PR!
Is it necessary to introduce c_REMOVED_ABBREVS
? I tried just removing it altogether, i.e.
diff --git a/pandas/_libs/tslibs/dtypes.pxd b/pandas/_libs/tslibs/dtypes.pxd
index 1ceb837d39..d8c536a34b 100644
--- a/pandas/_libs/tslibs/dtypes.pxd
+++ b/pandas/_libs/tslibs/dtypes.pxd
@@ -14,7 +14,6 @@ cdef bint is_supported_unit(NPY_DATETIMEUNIT reso)
cdef dict c_OFFSET_TO_PERIOD_FREQSTR
cdef dict c_PERIOD_TO_OFFSET_FREQSTR
cdef dict c_OFFSET_RENAMED_FREQSTR
-cdef dict c_REMOVED_ABBREVS
cdef dict c_DEPR_UNITS
cdef dict c_PERIOD_AND_OFFSET_DEPR_FREQSTR
cdef dict attrname_to_abbrevs
diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx
index 08a398f7a3..f1cb5ce9fb 100644
--- a/pandas/_libs/tslibs/dtypes.pyx
+++ b/pandas/_libs/tslibs/dtypes.pyx
@@ -335,14 +335,6 @@ PERIOD_TO_OFFSET_FREQSTR = {
cdef dict c_OFFSET_TO_PERIOD_FREQSTR = OFFSET_TO_PERIOD_FREQSTR
cdef dict c_PERIOD_TO_OFFSET_FREQSTR = PERIOD_TO_OFFSET_FREQSTR
-# Map deprecated resolution abbreviations to correct resolution abbreviations
-cdef dict c_REMOVED_ABBREVS = {
- "H": "h",
- "BH": "bh",
- "CBH": "cbh",
- "S": "s",
-}
-
cdef dict c_DEPR_UNITS = {
"w": "W",
"d": "D",
@@ -451,9 +443,7 @@ class Resolution(Enum):
True
"""
try:
- if freq in c_REMOVED_ABBREVS:
- raise ValueError(INVALID_FREQ_ERR_MSG.format(freq))
attr_name = _abbrev_to_attrnames[freq]
except KeyError:
# For quarterly and yearly resolutions, we need to chop off
@@ -464,8 +454,6 @@ class Resolution(Enum):
if split_freq[1] not in _month_names:
# i.e. we want e.g. "Q-DEC", not "Q-INVALID"
raise
- if split_freq[0] in c_REMOVED_ABBREVS:
- raise ValueError(INVALID_FREQ_ERR_MSG.format(split_freq[0]))
attr_name = _abbrev_to_attrnames[split_freq[0]]
return cls.from_attrname(attr_name)
diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx
index a30d738cc1..6e17f8f6ae 100644
--- a/pandas/_libs/tslibs/offsets.pyx
+++ b/pandas/_libs/tslibs/offsets.pyx
@@ -60,7 +60,6 @@ from pandas._libs.tslibs.dtypes cimport (
c_OFFSET_TO_PERIOD_FREQSTR,
c_PERIOD_AND_OFFSET_DEPR_FREQSTR,
c_PERIOD_TO_OFFSET_FREQSTR,
- c_REMOVED_ABBREVS,
periods_per_day,
)
from pandas._libs.tslibs.nattype cimport (
@@ -4908,8 +4907,6 @@ cpdef to_offset(freq, bint is_period=False):
if not stride:
stride = 1
- if prefix in c_REMOVED_ABBREVS:
- raise ValueError(INVALID_FREQ_ERR_MSG.format(prefix))
if prefix in {"D", "h", "min", "s", "ms", "us", "ns"}:
# For these prefixes, we have something like "3h" or
and it seems fine, did I miss something?
In
pandas/pandas/_libs/tslibs/dtypes.pyx
Lines 447 to 457 in 7d2980c
>>> Resolution.get_reso_from_freqstr('h') | |
<Resolution.RESO_HR: 5> | |
>>> Resolution.get_reso_from_freqstr('h') == Resolution.RESO_HR | |
True | |
""" | |
try: | |
if freq in c_REMOVED_ABBREVS: | |
raise ValueError(INVALID_FREQ_ERR_MSG.format(freq)) | |
attr_name = _abbrev_to_attrnames[freq] |
you may also want to change raise
to something like raise ValueError(err_msg) from exc
, where exc
is the KeyError
?
…yError in get_reso_from_freqstr
This reverts commit 4085d5c.
4a3e0de
to
412ab91
Compare
thanks, @MarcoGorelli for helping me with this PR. You are right, there is no need to have |
thanks, I did as you suggested and replaced
|
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.
thanks @natmokval , looks good to me, nice to see things get simpler
Thanks @natmokval |
Enforced deprecation of uppercase strings ‘H’, ‘BH’, ‘CBH’ for offsets frequencies, resolution abbreviations, and units in favor of 'h', 'bh', 'cbh'