Skip to content

DOC: point out that only period frequencies are valid for to_period #53477

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 1 commit into from
Jun 1, 2023

Conversation

natmokval
Copy link
Contributor

@natmokval natmokval commented May 31, 2023

Updated docs for to_period. Point out that only period frequencies are valid for to_period. For example, offset frequency 'MS' isn't valid for to_period.

>>> df = pd.DataFrame({"y": [1, 2]}, `index=pd.to_datetime(["2000-03-31` 00:00:00", "2000-05-31 00:00:00"]))
>>> df.index.to_period("MS")
AttributeError: 'pandas._libs.tslibs.offsets.MonthBegin' object has no attribute '_period_dtype_code'

Maybe it would be better to have 2 different tables, for offset aliases and period aliases, instead of this one for offset aliases?

@natmokval natmokval marked this pull request as ready for review May 31, 2023 23:16
@mroeschke mroeschke added Docs Period Period data type labels Jun 1, 2023
@mroeschke mroeschke added this to the 2.1 milestone Jun 1, 2023
@mroeschke mroeschke merged commit 4fdd8b5 into pandas-dev:main Jun 1, 2023
@mroeschke
Copy link
Member

Thanks @natmokval

Maybe it would be better to have 2 different tables, for offset aliases and period aliases, instead of this one for offset aliases?

Yeah I think this would be useful. Do you have the offsets on-hand that don't work with Periods?

@natmokval
Copy link
Contributor Author

Thanks @natmokval

Yeah I think this would be useful. Do you have the offsets on-hand that don't work with Periods?

The aliases listed below don't work with period:

SM 'pandas._libs.tslibs.offsets.SemiMonthEnd' object has no attribute '_period_dtype_code'
BM 'pandas._libs.tslibs.offsets.BusinessMonthEnd' object has no attribute '_period_dtype_code'
CBM 'pandas._libs.tslibs.offsets.CustomBusinessMonthEnd' object has no attribute '_period_dtype_code'
MS 'pandas._libs.tslibs.offsets.MonthBegin' object has no attribute '_period_dtype_code'
SMS 'pandas._libs.tslibs.offsets.SemiMonthBegin' object has no attribute '_period_dtype_code'
BMS 'pandas._libs.tslibs.offsets.BusinessMonthBegin' object has no attribute '_period_dtype_code'
CBMS 'pandas._libs.tslibs.offsets.CustomBusinessMonthBeg' object has no attribute '_period_dtype_code'
BQ 'pandas._libs.tslibs.offsets.BQuarterEnd' object has no attribute '_period_dtype_code'
QS 'pandas._libs.tslibs.offsets.QuarterBegin' object has no attribute '_period_dtype_code'
BQS 'pandas._libs.tslibs.offsets.BQuarterBegin' object has no attribute '_period_dtype_code'
BA 'pandas._libs.tslibs.offsets.BYearEnd' object has no attribute '_period_dtype_code'
BY 'pandas._libs.tslibs.offsets.BYearEnd' object has no attribute '_period_dtype_code'
AS 'pandas._libs.tslibs.offsets.YearBegin' object has no attribute '_period_dtype_code'
YS 'pandas._libs.tslibs.offsets.YearBegin' object has no attribute '_period_dtype_code'
BAS 'pandas._libs.tslibs.offsets.BYearBegin' object has no attribute '_period_dtype_code'
BYS 'pandas._libs.tslibs.offsets.BYearBegin' object has no attribute '_period_dtype_code'
BH 'pandas._libs.tslibs.offsets.BusinessHour' object has no attribute '_period_dtype_code'

topper-123 pushed a commit to topper-123/pandas that referenced this pull request Jun 5, 2023
…andas-dev#53477)

point out that only period frequencies are valid for  to_period
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
…andas-dev#53477)

point out that only period frequencies are valid for  to_period
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants