Skip to content

Commit 9bca038

Browse files
keshavramaswamyjorisvandenbossche
authored andcommitted
[Backport pandas-dev#14452] DOC: updated docstring in .to_datetime() for out-of-bounds timestamps
with errors='ignore' closes pandas-dev#14448 Author: Keshav Ramaswamy <[email protected]> Author: Keshav Ramaswamy <[email protected]> Closes pandas-dev#14452 from keshavramaswamy/master and squashes the following commits: 5468fc5 [Keshav Ramaswamy] added link to timestamp limitations in docstring 3aa78cf [Keshav Ramaswamy] edit docstring to fit python standards 8bfa58e [Keshav Ramaswamy] edited docstring to fit python standards 5ed8ef5 [Keshav Ramaswamy] edut docstring to fit Python Standards 7402de4 [Keshav Ramaswamy] edited docstring to fit python standards c16ad6b [Keshav Ramaswamy] added timestamp limitations and default behavior to docstring 0db07b5 [Keshav Ramaswamy] updated docstring in .to_datetime() (cherry picked from commit 18fba53)
1 parent b2e8126 commit 9bca038

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pandas/tseries/tools.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _infer(a, b):
4343
raise AssertionError('Inputs must both have the same timezone,'
4444
' {0} != {1}'.format(tz, b.tzinfo))
4545
return tz
46+
4647
tz = None
4748
if start is not None:
4849
tz = _infer(start, end)
@@ -267,10 +268,15 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
267268
1 2016-03-05
268269
dtype: datetime64[ns]
269270
270-
If a date that does not meet timestamp limitations, passing errors='coerce'
271-
will force to NaT. Furthermore this will force non-dates to NaT as well.
271+
If a date does not meet the `timestamp limitations
272+
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html
273+
#timeseries-timestamp-limits>`_, passing errors='ignore'
274+
will return the original input instead of raising any exception.
275+
276+
Passing errors='coerce' will force an out-of-bounds date to NaT,
277+
in addition to forcing non-dates (or non-parseable dates) to NaT.
272278
273-
>>> pd.to_datetime('13000101', format='%Y%m%d')
279+
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore')
274280
datetime.datetime(1300, 1, 1, 0, 0)
275281
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce')
276282
NaT
@@ -423,6 +429,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
423429

424430
return _convert_listlike(np.array([arg]), box, format)[0]
425431

432+
426433
# mappings for assembling units
427434
_unit_map = {'year': 'year',
428435
'years': 'year',
@@ -555,7 +562,7 @@ def calc_with_mask(carg, mask):
555562
result = np.empty(carg.shape, dtype='M8[ns]')
556563
iresult = result.view('i8')
557564
iresult[~mask] = tslib.iNaT
558-
result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)).\
565+
result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)). \
559566
astype('M8[ns]')
560567
return result
561568

@@ -640,7 +647,6 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
640647
DateParseError = tslib.DateParseError
641648
normalize_date = tslib.normalize_date
642649

643-
644650
# Fixed time formats for time parsing
645651
_time_formats = ["%H:%M", "%H%M", "%I:%M%p", "%I%M%p",
646652
"%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"]
@@ -766,6 +772,7 @@ def format(dt):
766772
"""Returns date in YYYYMMDD format."""
767773
return dt.strftime('%Y%m%d')
768774

775+
769776
OLE_TIME_ZERO = datetime(1899, 12, 30, 0, 0, 0)
770777

771778

0 commit comments

Comments
 (0)