-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ERR: better error message on unparseable datetimes #31118
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 3 commits
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 |
---|---|---|
|
@@ -480,6 +480,17 @@ def test_to_datetime_unparseable_ignore(self): | |
s = "Month 1, 1999" | ||
assert pd.to_datetime(s, errors="ignore") == s | ||
|
||
def test_to_datetime_unparseable_raise(self): | ||
# GH#10720 | ||
date = "Month 1, 1999" | ||
expected_args = ( | ||
f"Unknown string format: %s {date}. " | ||
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 believe that the error is here, can you remove 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. this looks likely 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.
|
||
"You can coerce to NaT by passing errors='coerce'" | ||
) | ||
|
||
with pytest.raises(ValueError, match=expected_args): | ||
pd.to_datetime(date, errors="raise") | ||
|
||
@td.skip_if_windows # `tm.set_timezone` does not work in windows | ||
def test_to_datetime_now(self): | ||
# See GH#18666 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,16 @@ def test_to_timedelta_invalid(self): | |
invalid_data, to_timedelta(invalid_data, errors="ignore") | ||
) | ||
|
||
# GH#10720 | ||
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. can you make a new test 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.
|
||
invalid_data = "some_nonesense" | ||
expected_msg = ( | ||
"unit abbreviation w/o a number. " | ||
"You can coerce to NaT by passing errors='coerce'" | ||
) | ||
|
||
with pytest.raises(ValueError, match=expected_msg): | ||
to_timedelta(invalid_data, errors="raise") | ||
|
||
def test_to_timedelta_via_apply(self): | ||
# GH 5458 | ||
expected = Series([np.timedelta64(1, "s")]) | ||
|
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.
call this msg
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.
Ok.