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

Update timestamps.pyi #818

Closed
wants to merge 1 commit into from
Closed

Update timestamps.pyi #818

wants to merge 1 commit into from

Conversation

davetapley
Copy link
Contributor

pandas-dev/pandas@f3c46cd

pandas-dev/pandas#48819

#797

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.

Can you add tests for this?

Copy link
Contributor Author

@davetapley davetapley left a 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 🙏🏻

Comment on lines +305 to +306
def unit(self) -> str: ...
def as_unit(self, unit: str, round_ok: bool = ...) -> Timestamp: ...
Copy link
Collaborator

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:

  1. Add that line to pandas-stubs/_typing.pyi
  2. Make the return value of unit be TimeUnit
  3. Make the allowable values of unit in as_unit to be TimeUnit

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 12, 2024

Closing in favor of #864

@Dr-Irv Dr-Irv closed this Feb 12, 2024
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.

"Timestamp" has no attribute "as_unit" [attr-defined]
2 participants