-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
to_datetime returns NaT for old dates with coerce=True #9107
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
Comments
I believe this is intentional, although it is poorly documented. The return value in the second case is a |
To be clear, this (old dates) is a case where |
this is correct, the 2nd is a not a bug. let's turn this to a further update to the docs (see #8921). @vfilimonov want to do this? |
Docstring: pd.to_datetime (issue #9107)
as of 1.0.0-dev this looks to be resolved: pd.to_datetime('13000101', format='%Y%m%d')
...
~/pandas-squigmig/pandas/core/tools/datetimes.py in _convert_listlike_datetimes(arg, box, format, name, tz, unit, errors, infer_datetime_format, dayfirst, yearfirst, exact)
412 try:
413 result, timezones = array_strptime(
--> 414 arg, format, exact=exact, errors=errors
415 )
416 if "%Z" in format or "%z" in format:
~/pandas-squigmig/pandas/_libs/tslibs/strptime.pyx in pandas._libs.tslibs.strptime.array_strptime()
335 iresult[i] = NPY_NAT
336 continue
--> 337 raise
338
339 result_timezone[i] = timezone
~/pandas-squigmig/pandas/_libs/tslibs/strptime.pyx in pandas._libs.tslibs.strptime.array_strptime()
330 iresult[i] = dtstruct_to_dt64(&dts)
331 try:
--> 332 check_dts_bounds(&dts)
333 except ValueError:
334 if is_coerce:
~/pandas-squigmig/pandas/_libs/tslibs/np_datetime.pyx in pandas._libs.tslibs.np_datetime.check_dts_bounds()
116 dts.day, dts.hour,
117 dts.min, dts.sec)
--> 118 raise OutOfBoundsDatetime(
119 'Out of bounds nanosecond timestamp: {fmt}'.format(fmt=fmt))
120
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1300-01-01 00:00:00 |
test to ensure OutOfBoundsDatetime exception is raised when calling pd.to_datetime with out-of-bounds date strings
When use
coerce=True
inpandas.to_datetime
old dates (before 1677-09-22) return NaT. The same dates withoutcoerce
are parsed correctly:returns
pandas: 0.15.2
numpy: 1.9.1
The text was updated successfully, but these errors were encountered: