Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.period_range('2000', periods=3, freq='M').to_timestamp('M')
Issue Description
The docs say
Cast to DatetimeIndex of timestamps, at beginning of period.
A Period(freq='M')
starts at the beginning of the month, and ends on the last moment before the next month:
In [7]: pd.Period('2000', freq='M').start_time
Out[7]: Timestamp('2000-01-01 00:00:00')
In [8]: pd.Period('2000', freq='M').end_time
Out[8]: Timestamp('2000-01-31 23:59:59.999999999')
Expected Behavior
So, I'd have expected the above to output
DatetimeIndex(['2000-01-01', '2000-02-01', '2000-03-01'], dtype='datetime64[ns]', freq='MS')
Instead, we get
DatetimeIndex(['2000-01-31', '2000-02-29', '2000-03-31'], dtype='datetime64[ns]', freq='ME')
This looks odd. But, it's also been like that since as far back as I tested (i.e. pandas 0.25.3 😱 )
>>> import pandas as pd
>>> pd.period_range('2000', periods=3, freq='M').to_timestamp('M')
DatetimeIndex(['2000-01-31', '2000-02-29', '2000-03-31'], dtype='datetime64[ns]', freq='M')
>>> pd.__version__
'0.25.3'
Urgh, now what.
Splitting this off from https://github.com/pandas-dev/pandas/issues/58974
Installed Versions
Comment From: MarcoGorelli
I think this should be treated as a bug and just fixed in 3.0? will investigate more closely
Comment From: aram-cedarwood
take