Skip to content

DOC:updated docstring in .to_datetime() #14452

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

Closed
wants to merge 7 commits into from
Closed
20 changes: 13 additions & 7 deletions pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _infer(a, b):
raise AssertionError('Inputs must both have the same timezone,'
' {0} != {1}'.format(tz, b.tzinfo))
return tz

tz = None
if start is not None:
tz = _infer(start, end)
Expand Down Expand Up @@ -266,11 +267,15 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
0 2015-02-04
1 2016-03-05
dtype: datetime64[ns]

If a date that does not meet timestamp limitations, passing errors='coerce'
will force to NaT. Furthermore this will force non-dates to NaT as well.

>>> pd.to_datetime('13000101', format='%Y%m%d')

If a date that does not meet `timestamp limitations
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html
#timeseries-timestamp-limits>`_, passing errors='ignore'
will simply return the original input instead of raising any exception.
Passing errors='coerce' will force to NaT. Furthermore this will force
non-dates to NaT as well.

>>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's nice to add an example of default behavior, and describe what the timestamp limitation is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sinhrks sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u add it to the docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense - I'll do that!

datetime.datetime(1300, 1, 1, 0, 0)
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce')
NaT
Expand Down Expand Up @@ -423,6 +428,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):

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


# mappings for assembling units
_unit_map = {'year': 'year',
'years': 'year',
Expand Down Expand Up @@ -555,7 +561,7 @@ def calc_with_mask(carg, mask):
result = np.empty(carg.shape, dtype='M8[ns]')
iresult = result.view('i8')
iresult[~mask] = tslib.iNaT
result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)).\
result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)). \
astype('M8[ns]')
return result

Expand Down Expand Up @@ -640,7 +646,6 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
DateParseError = tslib.DateParseError
normalize_date = tslib.normalize_date


# Fixed time formats for time parsing
_time_formats = ["%H:%M", "%H%M", "%I:%M%p", "%I%M%p",
"%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"]
Expand Down Expand Up @@ -766,6 +771,7 @@ def format(dt):
"""Returns date in YYYYMMDD format."""
return dt.strftime('%Y%m%d')


OLE_TIME_ZERO = datetime(1899, 12, 30, 0, 0, 0)


Expand Down