Skip to content

Commit 18fba53

Browse files
keshavramaswamyjreback
authored andcommitted
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()
1 parent 192b1cd commit 18fba53

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
@@ -42,6 +42,7 @@ def _infer(a, b):
4242
raise AssertionError('Inputs must both have the same timezone,'
4343
' {0} != {1}'.format(tz, b.tzinfo))
4444
return tz
45+
4546
tz = None
4647
if start is not None:
4748
tz = _infer(start, end)
@@ -264,10 +265,15 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
264265
1 2016-03-05
265266
dtype: datetime64[ns]
266267
267-
If a date that does not meet timestamp limitations, passing errors='coerce'
268-
will force to NaT. Furthermore this will force non-dates to NaT as well.
268+
If a date does not meet the `timestamp limitations
269+
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html
270+
#timeseries-timestamp-limits>`_, passing errors='ignore'
271+
will return the original input instead of raising any exception.
272+
273+
Passing errors='coerce' will force an out-of-bounds date to NaT,
274+
in addition to forcing non-dates (or non-parseable dates) to NaT.
269275
270-
>>> pd.to_datetime('13000101', format='%Y%m%d')
276+
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore')
271277
datetime.datetime(1300, 1, 1, 0, 0)
272278
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce')
273279
NaT
@@ -420,6 +426,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
420426

421427
return _convert_listlike(np.array([arg]), box, format)[0]
422428

429+
423430
# mappings for assembling units
424431
_unit_map = {'year': 'year',
425432
'years': 'year',
@@ -552,7 +559,7 @@ def calc_with_mask(carg, mask):
552559
result = np.empty(carg.shape, dtype='M8[ns]')
553560
iresult = result.view('i8')
554561
iresult[~mask] = tslib.iNaT
555-
result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)).\
562+
result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)). \
556563
astype('M8[ns]')
557564
return result
558565

@@ -637,7 +644,6 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
637644
DateParseError = tslib.DateParseError
638645
normalize_date = tslib.normalize_date
639646

640-
641647
# Fixed time formats for time parsing
642648
_time_formats = ["%H:%M", "%H%M", "%I:%M%p", "%I%M%p",
643649
"%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"]
@@ -763,6 +769,7 @@ def format(dt):
763769
"""Returns date in YYYYMMDD format."""
764770
return dt.strftime('%Y%m%d')
765771

772+
766773
OLE_TIME_ZERO = datetime(1899, 12, 30, 0, 0, 0)
767774

768775

0 commit comments

Comments
 (0)