Skip to content

DOC: pd.Period and pd.period_range should document that they accept datetime, date and pd.Timestamp #53038

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
1 task done
Daverball opened this issue May 2, 2023 · 1 comment · Fixed by #53611 or #53632
Closed
1 task done
Assignees
Labels
datetime.date stdlib datetime.date support Docs Period Period data type Timestamp pd.Timestamp and associated methods

Comments

@Daverball
Copy link

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.Period.html#pandas-period
https://pandas.pydata.org/docs/reference/api/pandas.period_range.html#pandas-period-range

Documentation problem

Period documents the value argument as str or Period, while period_range will document it as str or period-like. Both just use the Period constructor implemented in cython internally. As per said implementation, it will also accept a datetime, date and pd.Timestamp as can be seen here: https://github.com/pandas-dev/pandas/blob/v2.0.1/pandas/_libs/tslibs/period.pyx#L2626-L2643

Technically it would also accept an integer/float, but this seems more of an edge case, so it might be fine to exclude it from the documentation, it's also not particularly helpful.

Suggested fix for documentation

Extend parameter documentation with additional allowed types. It might also be nice to mention that freq is required if value is not already period-like (i.e. a Period or a string representation of a period)

This issue was opened as a result of discussion on the following pandas-stubs issue: pandas-dev/pandas-stubs#675

@Daverball Daverball added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels May 2, 2023
@DeaMariaLeon DeaMariaLeon added Period Period data type datetime.date stdlib datetime.date support Timestamp pd.Timestamp and associated methods and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 3, 2023
@ABizzinotto
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datetime.date stdlib datetime.date support Docs Period Period data type Timestamp pd.Timestamp and associated methods
Projects
None yet
3 participants