-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Update timestamps.pyi #818
Conversation
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.
Can you add tests for 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.
Hope this is sufficient 🙏🏻
def unit(self) -> str: ... | ||
def as_unit(self, unit: str, round_ok: bool = ...) -> Timestamp: ... |
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.
The only possible values for the return of unit
are Literal["s", "ms", "us", "ns"]
In pandas, this is now defined in pandas._typing.py
via:
TimeUnit = Literal["s", "ms", "us", "ns"]
So can you do the following:
- Add that line to
pandas-stubs/_typing.pyi
- Make the return value of
unit
beTimeUnit
- Make the allowable values of
unit
inas_unit
to beTimeUnit
You probably will have to change the test for ts.unit
to use assert_type()
testing against TimeUnit
If you want to go beyond that, the declaration Literal["s", "ms", "us", "ns"]
appears in the following files and should be replaced with TimeUnit
:
- pandas-stubs/core/frame.pyi
- pandas-stubs/core/indexes/datetimes.pyi
- pandas-stubs/core/series.pyi
- pandas-stubs/io/json/_json.pyi
But if you don't want to make that change, it's OK - I can just create a new issue for that once this PR is done.
@@ -1530,6 +1531,8 @@ def test_timestamp_misc_methods() -> None: | |||
pd.Timestamp, | |||
) | |||
|
|||
check(assert_type(ts2.as_unit('ns'), pd.Timestamp), pd.Timestamp) |
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.
check(assert_type(ts2.as_unit('ns'), pd.Timestamp), pd.Timestamp) | |
check(assert_type(ts2.as_unit("ns"), pd.Timestamp), pd.Timestamp) |
use the pre-commit hook. You need double quotes here.
Closing in favor of #864 |
pandas-dev/pandas@f3c46cd
pandas-dev/pandas#48819
#797
assert_type()
to assert the type of any return value