Skip to content
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

BUG: PeriodIndex.to_datetime inconsistent with its docstring #59371

Open
3 tasks done
MarcoGorelli opened this issue Jul 31, 2024 · 2 comments · May be fixed by #60350
Open
3 tasks done

BUG: PeriodIndex.to_datetime inconsistent with its docstring #59371

MarcoGorelli opened this issue Jul 31, 2024 · 2 comments · May be fixed by #60350
Assignees
Labels
Bug Frequency DateOffsets

Comments

@MarcoGorelli
Copy link
Member

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • 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 #58974

Installed Versions

INSTALLED VERSIONS

commit : b552dc9
python : 3.10.12
python-bits : 64
OS : Linux
OS-release : 5.15.153.1-microsoft-standard-WSL2
Version : #1 SMP Fri Mar 29 23:14:13 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 3.0.0.dev0+618.gb552dc95c9
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 24.0
Cython : 3.0.9
sphinx : 7.2.6
IPython : 8.22.2
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.3.8
fastparquet : 2024.2.0
fsspec : 2024.3.1
html5lib : 1.1
hypothesis : 6.99.13
gcsfs : 2024.3.1
jinja2 : 3.1.3
lxml.etree : 5.1.0
matplotlib : 3.8.3
numba : 0.59.1
numexpr : 2.9.0
odfpy : None
openpyxl : 3.1.2
psycopg2 : 2.9.9
pymysql : 1.4.6
pyarrow : 16.1.0
pyreadstat : 1.2.7
pytest : 8.1.1
python-calamine : None
pyxlsb : 1.0.10
s3fs : 2024.3.1
scipy : 1.12.0
sqlalchemy : 2.0.29
tables : 3.9.2
tabulate : 0.9.0
xarray : 2024.2.0
xlrd : 2.0.1
xlsxwriter : 3.2.0
zstandard : 0.22.0
tzdata : 2024.1
qtpy : None
pyqt5 : None

@MarcoGorelli MarcoGorelli added Bug Needs Triage Issue that has not been reviewed by a pandas team member Frequency DateOffsets and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 31, 2024
@MarcoGorelli
Copy link
Member Author

I think this should be treated as a bug and just fixed in 3.0? will investigate more closely

@aram-cinnamon
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
2 participants