-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
ERR: Raise the correct error for to_datetime() #23969
Changes from all commits
d9c1918
f6c1efa
cefb1c1
b3fadc6
399beca
d7adb56
8d8b893
6aa0bf3
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 |
---|---|---|
|
@@ -599,11 +599,9 @@ cpdef array_to_datetime(ndarray[object] values, str errors='raise', | |
iresult[i] = NPY_NAT | ||
continue | ||
elif is_raise: | ||
raise ValueError("time data {val} doesn't " | ||
"match format specified" | ||
.format(val=val)) | ||
raise | ||
return values, tz_out | ||
|
||
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. don't add extra whitespace |
||
try: | ||
py_dt = parse_datetime_string(val, | ||
dayfirst=dayfirst, | ||
|
@@ -661,7 +659,7 @@ cpdef array_to_datetime(ndarray[object] values, str errors='raise', | |
else: | ||
raise TypeError("{typ} is not convertible to datetime" | ||
.format(typ=type(val))) | ||
|
||
except OutOfBoundsDatetime: | ||
if is_coerce: | ||
iresult[i] = NPY_NAT | ||
|
@@ -671,9 +669,7 @@ cpdef array_to_datetime(ndarray[object] values, str errors='raise', | |
# dateutil parser will return incorrect result because | ||
# it will ignore nanoseconds | ||
if is_raise: | ||
raise ValueError("time data {val} doesn't " | ||
"match format specified" | ||
.format(val=val)) | ||
raise | ||
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. I agree this is legit. can you add a comment here about this, e.g. its OOB (even though its just a few lines above) |
||
assert is_ignore | ||
return values, tz_out | ||
raise | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -960,6 +960,17 @@ def test_to_datetime_barely_out_of_bounds(self): | |
with pytest.raises(OutOfBoundsDatetime): | ||
to_datetime(arr) | ||
|
||
def test_to_datetime_out_of_bounds_with_format_arg(self): | ||
# GH#23830 raise the correct exception when | ||
# the format argument is passed. | ||
msg = r"Out of bounds nanosecond timestamp" | ||
with pytest.raises( | ||
OutOfBoundsDatetime, | ||
match=msg | ||
): | ||
to_datetime("2417-10-27 00:00:00", | ||
format="%Y-%m-%d %H:%M:%S") | ||
|
||
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. Move this out as a separate test and reference the issue number. Also, check the error here with the 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. Thanks for the feedback. I'll move it out. However, my main issue here was that this test would pass locally but fail on the CI build (https://travis-ci.org/pandas-dev/pandas/jobs/460708541). My best guess was that it was due to 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. Your build may not have had this added test, as I'm relatively certain that your change above was not correct. |
||
@pytest.mark.parametrize('cache', [True, False]) | ||
def test_to_datetime_iso8601(self, cache): | ||
result = to_datetime(["2012-01-01 00:00:00"], cache=cache) | ||
|
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 dont' think think this case is actually an OOB error, rather a parsing error.