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

Add unit property and as_unit method to DatetimeIndex, TimedeltaIndex and Series.dt #865

Conversation

skatsuta
Copy link
Contributor

@skatsuta skatsuta commented Feb 12, 2024

  • Tests added: Please use assert_type() to assert the type of any return value

Add unit property and as_unit method to DatetimeIndex, TimedeltaIndex and Series.dt,
to add support for the following items in #624:

Note: The addition to TimelikeOps is not necessarily needed to add support for Series.dt, but since it is in the pandas implementation, we should also add it in this stub for consistency.

@skatsuta skatsuta force-pushed the add-as-unit-to-datetimeindex-timedeltaindex-series-dt branch from dc1dace to cd35a2f Compare February 12, 2024 06:48
Comment on lines -157 to +159
_DTRoundingMethodReturnType = TypeVar(
"_DTRoundingMethodReturnType",
_DTTimestampTimedeltaReturnType = TypeVar(
"_DTTimestampTimedeltaReturnType",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rename to a general name to reuse this type var in the return type annotation for as_unit method

@skatsuta skatsuta marked this pull request as ready for review February 12, 2024 06:59
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

As suggested in #864 , can you use TimeUnit throughout instead of Literal

Otherwise, this looks OK

@skatsuta skatsuta force-pushed the add-as-unit-to-datetimeindex-timedeltaindex-series-dt branch from cd35a2f to 9120dce Compare February 13, 2024 14:54
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @skatsuta

@Dr-Irv Dr-Irv merged commit a51279e into pandas-dev:main Feb 13, 2024
13 checks passed
@skatsuta skatsuta deleted the add-as-unit-to-datetimeindex-timedeltaindex-series-dt branch February 13, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants