-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: avoid overflow in Bday generate_range, closes #24252 #26651
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26651 +/- ##
==========================================
- Coverage 91.87% 91.87% -0.01%
==========================================
Files 174 174
Lines 50692 50696 +4
==========================================
+ Hits 46575 46576 +1
- Misses 4117 4120 +3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26651 +/- ##
==========================================
- Coverage 91.87% 91.86% -0.02%
==========================================
Files 180 180
Lines 50746 50751 +5
==========================================
- Hits 46623 46621 -2
- Misses 4123 4130 +7
Continue to review full report at Codecov.
|
This doesn't solve the overflow type: >>> date = pd.Timestamp.max.floor("D").to_pydatetime().date() # datetime.date(2262, 4, 11)
>>> freq = 'B'
>>> pd.date_range(date, periods=2, freq=freq) # see periods=2
OverflowError: int too big to convert I would guess this should be a |
Yah, it should probably be an OutOfBoundsDatetime instead of OverflowError. Will update. |
pandas/_libs/tslibs/timestamps.pyx
Outdated
ts = convert_to_tsobject(ts_input, tz, unit, 0, 0, nanosecond or 0) | ||
try: | ||
ts = convert_to_tsobject(ts_input, tz, unit, 0, 0, nanosecond or 0) | ||
except OverflowError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you update the doc-string of convert_ot_tsobject. Why are we not catching the OverflowError inside?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this here because I wanted to do this error-catching in python-space instead of c-space so that convert_to_tsobject could have better optimizations, but it looks like convert_to_tsobject already has some raising cases, so this can be moved there. will update.
lgtm. ping when green. |
code & tests lgtm. can you add a whatsnew. ping on green. |
ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comment, otherwise lgtm.
pandas/_libs/tslibs/timestamps.pyx
Outdated
@@ -24,6 +24,7 @@ from pandas._libs.tslibs.conversion cimport ( | |||
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT | |||
from pandas._libs.tslibs.np_datetime cimport ( | |||
check_dts_bounds, npy_datetimestruct, dt64_to_dtstruct) | |||
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, removed.
I'm holding out hope that one day we'll be able to lint these files.
In one Travis build I'm seeing an error I also get locally on many branches:
Any idea what this is all about? |
Not sure, but |
Looks like we import ma.mrecords as a runtime import in the DataFrame constructor, so this ma.mrecords will not exist if we run these tests before that runtime import gets hit. (I'm guessing we started randomizing test order recently?). Just added the import in the appropriate place in the test so it shouldn't matter anymore. |
pandas/_libs/tslibs/conversion.pyx
Outdated
ts = <int64_t>ts | ||
except OverflowError: | ||
# GH#26651 re-raise as OutOfBoundsDatetime | ||
raise OutOfBoundsDatetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is including the bad ts
in the exception message useful here? I imagine it's good for Timestamp(too_big_int)
, but not so much for other inputs (if they hit this).
thanks @jbrockmendel nice patch! |
git diff upstream/master -u -- "*.py" | flake8 --diff