Skip to content
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: Correct error message in to_datetime #25467

Merged
merged 2 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ Performance Improvements

Bug Fixes
~~~~~~~~~

- Bug in :func:`to_datetime` which would raise an (incorrect) ``ValueError`` when called with a date far into the future and the ``format`` argument specified instead of raising ``OutOfBoundsDatetime`` (:issue:`23830`)
-
-

Categorical
Expand Down
8 changes: 5 additions & 3 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,11 @@ 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))

# Still raise OutOfBoundsDatetime,
# as error message is informative.
raise

assert is_ignore
return values, tz_out
raise
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,16 @@ def test_invalid_origins_tzinfo(self):
pd.to_datetime(1, unit='D',
origin=datetime(2000, 1, 1, tzinfo=pytz.utc))

@pytest.mark.parametrize("kwargs", [
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
dict(),
dict(format="%Y-%m-%d %H:%M:%S")
])
def test_to_datetime_out_of_bounds_with_format_arg(self, kwargs):
# see gh-23830
msg = "Out of bounds nanosecond timestamp"
with pytest.raises(OutOfBoundsDatetime, match=msg):
to_datetime("2417-10-27 00:00:00", **kwargs)

def test_processing_order(self):
# make sure we handle out-of-bounds *before*
# constructing the dates
Expand Down