Skip to content

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

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,7 @@ class Period(_Period):
One of pandas period strings or corresponding objects. Accepted
strings are listed in the
:ref:`offset alias section <timeseries.offset_aliases>` in the user docs.
If value is not already period-like, freq is required.
Copy link
Member

@MarcoGorelli MarcoGorelli Jun 13, 2023

Choose a reason for hiding this comment

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

are you sure this is true? e.g. here I don't specify freq

In [1]: pd.Period('2020-01')
Out[1]: Period('2020-01', 'M')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarcoGorelli thanks. Good point, it works with a string, it just errors if value is None or datetime. Changed the note to reflect that.

Copy link
Member

Choose a reason for hiding this comment

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

thanks - looks fine for None though?

In [3]: pd.Period(None)
Out[3]: NaT

Copy link
Member

Choose a reason for hiding this comment

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

hi - is this still active? if so, could you address this comment please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, missed this comment. I believe it should be all set now

ordinal : int, default None
The period offset from the proleptic Gregorian epoch.
year : int, default None
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def period_range(
----------
start : str, datetime, date, pandas.Timestamp, or period-like, default None
Left bound for generating periods.
end : str or period-like, default None
end : str, datetime, date, pandas.Timestamp, or period-like, default None
Right bound for generating periods.
periods : int, default None
Number of periods to generate.
Expand Down