-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
API/BUG: freq retention in value_counts #62532
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
base: main
Are you sure you want to change the base?
Conversation
pandas/core/algorithms.py
Outdated
and hasattr(values, "freq") | ||
and values.freq is not None |
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.
and hasattr(values, "freq") | |
and values.freq is not None | |
and hasattr(values, "freq") | |
and values.freq is not None |
Instead could you isinstance(values, DatetimeIndex)
(you might need a local import of DatetimeIndex
). Also you can use values.inferred_freq
to get the frequency instead
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 the suggestion. values.inferred_freq makes sense!
However, my assumption was that we want to make it more generic and not localise this fix to just DatetimeIndex. Please could you help me understand this?
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.
DatetimeIndex
is the only relevant object that requires frequency preservation, so it's OK to special case here
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.
Got it!
I have also added TimedeltaIndex as that was one of the examples given in the issue for frequency preservation. Let me know if that makes sense.
doc/source/whatsnew/v3.0.0.rst
file if fixing a bug or adding a new feature.