-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Improve to_datetime bounds checking #50183
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
Changes from 2 commits
f3d0d15
dff5a3e
9fe5091
bac5f68
535a4ec
e0b9a8f
a5012a9
088eda5
8b9c050
400bb22
8ebc910
5ccb96a
c17883e
4bd1e2a
bf5542e
2795783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1629,6 +1629,27 @@ def test_to_timestamp_unit_coerce(self, bad_val): | |
result = to_datetime([1, 2, bad_val], unit="D", errors="coerce") | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_float_to_datetime_raise_near_bounds(self): | ||
mag="cannot convert input with unit 'Y'" | ||
oneyear_in_ns = 1e9 * 60 * 60 * 24 * 365.2425 | ||
tsmax_in_years = 2**63 / oneyear_in_ns # 2**63 ns, in years | ||
should_succeed = Series( | ||
[0, tsmax_in_years - 0.05, -tsmax_in_years + 0.05], | ||
dtype=float | ||
) | ||
should_fail1 = Series([0, tsmax_in_years + 0.05], dtype=float) | ||
should_fail2 = Series([0, -tsmax_in_years - 0.05], dtype=float) | ||
|
||
result1=to_datetime(should_succeed, unit="Y", errors='raise') | ||
result2=to_datetime(should_succeed, unit="Y", errors='coerce') | ||
result3=to_datetime(should_succeed, unit="Y", errors='ignore') | ||
tm.assert_series_equal(result1, result2) | ||
tm.assert_series_equal(result1, result3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A check that compared to a non to_datetime correct value would be better, but there don't seem to be any "allclose" checks in this file, and using exact equality risks rounding error failing it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. (Possibly the reason there weren't any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reported that as #50191 |
||
with pytest.raises(OutOfBoundsDatetime, match=msg): | ||
to_datetime(should_fail1, unit="Y", errors='raise') | ||
with pytest.raises(OutOfBoundsDatetime, match=msg): | ||
to_datetime(should_fail2, unit="Y", errors='raise') | ||
|
||
|
||
class TestToDatetimeDataFrame: | ||
@pytest.fixture | ||
|
Uh oh!
There was an error while loading. Please reload this page.