Skip to content

period_range and Period should accept date, datetime and pd.Timestamp #675

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

Closed
Daverball opened this issue May 2, 2023 · 2 comments · Fixed by #728
Closed

period_range and Period should accept date, datetime and pd.Timestamp #675

Daverball opened this issue May 2, 2023 · 2 comments · Fixed by #728

Comments

@Daverball
Copy link
Contributor

pd.period_range and pd.Period currently only accept str and pd.Period as arguments, but the implementation also accepts datetime, date and pd.Timestamp as can be seen here in the cython implementation: https://github.com/pandas-dev/pandas/blob/v2.0.1/pandas/_libs/tslibs/period.pyx#L2626-L2643

It technically also allows integers/floats. period_range internally uses Period to convert the start and end arguments, so the type annotations can be used interchangeably between those two.

To Reproduce

import pandas as pd

pd.Period(pd.Timestamp('2020-01-01'), freq='Q')  # mypy: arg-type — Argument 1 to "Period" has incompatible type "Timestamp"
pd.period_range(pd.Timestamp('2020-01-01), '2020-06-01', freq='Q')  # mypy: arg-type — Argument 1 to "period_range" has incompatible type "Timestamp"
  • OS: Linux (OpenSUSE Tumbleweed)
  • Python 3.10
  • mypy 1.0.1
  • pandas-stubs 2.0.1.230501
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 2, 2023

For the stubs, we generally follow what is documented, and while the implementation does accept datetime, date, and pd.Timestamp, and maybe even int or float, the docs just say Period or str, so we'd have to find out if that is an error in the implementation or a documentation issue.

Can you open up an issue in the pandas repo about the docs, and once that is resolved, we can address the stubs?

Thanks.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 2, 2023

Can you open up an issue in the pandas repo about the docs, and once that is resolved, we can address the stubs?

Also, when you open that issue, please cross-reference this one.

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 a pull request may close this issue.

2 participants