Skip to content

Commit

Permalink
ERR: Correct error message in to_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Feb 28, 2019
1 parent c986386 commit 613af9e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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
5 changes: 2 additions & 3 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,8 @@ 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

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", [
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

0 comments on commit 613af9e

Please sign in to comment.