Skip to content

REGR: period_range giving incorrect values for large datetimes #36430

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
dsaxton opened this issue Sep 17, 2020 · 2 comments · Fixed by #36535
Closed

REGR: period_range giving incorrect values for large datetimes #36430

dsaxton opened this issue Sep 17, 2020 · 2 comments · Fixed by #36535
Labels
Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@dsaxton
Copy link
Member

dsaxton commented Sep 17, 2020

From the pandas-dev mailing list:

I encountered a bug in pandas 1.1.0 after updating from 1.0.5 that I wanted to pass along. If a period range is created that extends past the maximum timestamp date of 2262-04-11, then the period range is shifted back by an hour after this date. The screenshots below show an example with the shifted times highlighted in yellow.

import pandas as pd
from datetime import datetime

start = datetime(2000, 1, 1)
end = datetime(2500, 1, 1)

idx = pd.period_range(start, end, freq="6H")
assert idx[-1].hour % 2 == 0  # raises

idx
# PeriodIndex(['2000-01-01 00:00', '2000-01-01 06:00', '2000-01-01 12:00',
#              '2000-01-01 18:00', '2000-01-02 00:00', '2000-01-02 06:00',
#              '2000-01-02 12:00', '2000-01-02 18:00', '2000-01-03 00:00',
#              '2000-01-03 06:00',
#              ...
#              '2499-12-29 17:00', '2499-12-30 23:00', '2499-12-30 05:00',
#              '2499-12-30 11:00', '2499-12-30 17:00', '2499-12-31 23:00',
#              '2499-12-31 05:00', '2499-12-31 11:00', '2499-12-31 17:00',
#              '2500-01-01 23:00'],
#             dtype='period[6H]', length=730489, freq='6H')

pd.__version__
# '1.1.0'
@dsaxton dsaxton added Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version labels Sep 17, 2020
@dsaxton
Copy link
Member Author

dsaxton commented Sep 17, 2020

577de1c is the first bad commit
commit 577de1c
Author: jbrockmendel [email protected]
Date: Wed Apr 15 12:20:54 2020 -0700

REF: de-duplicate code in libperiod (#33491)

pandas/_libs/tslibs/period.pyx | 108 +++++++++++++++--------------------------
1 file changed, 39 insertions(+), 69 deletions(-)

PR #33491
cc @jbrockmendel

@jorisvandenbossche
Copy link
Member

@dsaxton if something is a regression compared to 1.0, you can always directly add a 1.1.x milestone (which doesn't mean it will get done of course, but then at least it shows up in the overview of issues that are good to have for the bug-fix release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants