Skip to content
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

DEPR: deprecate string H, BH, CBH in offsets frequencies, resolution abbreviations, _attrname_to_abbrevs #54939

Merged
merged 23 commits into from
Oct 8, 2023

Conversation

natmokval
Copy link
Contributor

@natmokval natmokval commented Sep 1, 2023

xref #54061

  • deprecated for Timedelta units 'H' in favour of 'h'
  • deprecated for time series frequencies aliases 'H', 'BH', 'CBH' in favour of 'h', 'bh', 'cbh'
  • deprecated resolution 'H' for Timedelta.resolution_string in favour of 'h'

@natmokval natmokval changed the title DEPR: deprecate string H in offsets frequencies, resolution abbreviations, _attrname_to_abbrevs DEPR: deprecate string H, BH, CBH in offsets frequencies, resolution abbreviations, _attrname_to_abbrevs Sep 13, 2023
@natmokval natmokval marked this pull request as ready for review September 19, 2023 18:23
@natmokval natmokval removed the request for review from MarcoGorelli September 19, 2023 18:53
@mroeschke mroeschke added Frequency DateOffsets Deprecate Functionality to remove in pandas labels Sep 25, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks for working on this - got a couple of minor comments, but this looks like it's pretty close

Comment on lines 2017 to 2019
if self._prefix.startswith(("C", "c")):
# CustomBusinessHour
return CustomBusinessDay(
Copy link
Member

Choose a reason for hiding this comment

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

should this one check for both? if it's business hour, don't we know it's going to start with 'c'?

Copy link
Contributor Author

@natmokval natmokval Sep 28, 2023

Choose a reason for hiding this comment

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

Thank you for reviewing this PR.

I think we need to check both: upper and lowercase 'c', because we added "cbh" to the dictionary _dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s", "me"}.
On the other hand, if freq is not in _dont_uppercase we do uppercasing in _get_offset().

When I remove the check for "c", tests for CustomBusinessHour fail.

Copy link
Member

Choose a reason for hiding this comment

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

thanks for explaining - the comment

            # CustomBusinessHour
            return CustomBusinessDay

might be a bit misleading, but I'll pull your code tomorrow, step through it, and check

the rest looks good though, so we should be very close

Copy link
Member

Choose a reason for hiding this comment

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

I had another look isn't _prefix always 'cbh' for CustomBusinessHour?

If so, then I think just checking if self._prefix.startswith("c"): should be enough? At least, if I do that, then pytest pandas/tests/tseries/offsets/ all passes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I agree, checking if self._prefix.startswith("c"): should be enough. I changed the condition, locally all tests passed.

pandas/_libs/tslibs/offsets.pyx Show resolved Hide resolved
pandas/tests/indexes/timedeltas/test_constructors.py Outdated Show resolved Hide resolved
@natmokval
Copy link
Contributor Author

I added tests for Hour and CustomBusinessHour and corrected the definition of to_offset. @MarcoGorelli, could you please take a look at the update?

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

looks good, just a couple of things I don't quite understand

Comment on lines 4654 to 4663
if prefix in c_DEPR_ABBREVS:
warnings.warn(
f"\'{prefix}\' is deprecated and will be removed "
f"in a future version. Please use "
f"\'{c_DEPR_ABBREVS.get(prefix)}\' "
f"instead of \'{prefix}\'.",
FutureWarning,
stacklevel=find_stack_level(),
)
prefix = c_DEPR_ABBREVS[prefix]
Copy link
Member

Choose a reason for hiding this comment

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

could you please explain why this needed to be moved here, from line 4642?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the check and transformation prefix = c_DEPR_ABBREVS[prefix] to keep it together with the call _get_offset in line 4666, where we use the new prefix.
I think it's not necessary, I can move it back.

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 was my mistake, I moved the check if prefix in c_DEPR_ABBREVS: back. Seems like we don't have a test to cover this case ,I added a test in PR "DEPR: 'A' in favour of 'Y'" that fails if the order of checks isn't correct.

Comment on lines 4664 to 4666
offset = _get_offset(name)
offset = _get_offset(prefix)
Copy link
Member

Choose a reason for hiding this comment

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

why did this change?

Copy link
Contributor Author

@natmokval natmokval Oct 3, 2023

Choose a reason for hiding this comment

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

we have tests that didn't work for BH / CBH because we changed prefix to bh / cbh in line 4663 prefix = c_DEPR_ABBREVS[prefix], but then passed to _get_offset name, = BH / CBH. That is why I replaced name with prefix.

@MarcoGorelli
Copy link
Member

looks like we're close, just got some conflicts from the A -> Y one (but I think you've mastered resolving conflicts now, so should be fine 😄 )

@natmokval
Copy link
Contributor Author

looks like we're close, just got some conflicts from the A -> Y one (but I think you've mastered resolving conflicts now, so should be fine 😄 )

thanks, I resolved conflicts, ci is green.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

looks solid, nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants