From 988397f15dc5458887e27af18520957b1d1b7cee Mon Sep 17 00:00:00 2001 From: Vladimir Filimonov Date: Fri, 2 Jan 2015 22:18:20 +0100 Subject: [PATCH 1/2] Docstring: pd.to_datetime (issue #9107) --- pandas/tseries/tools.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index e680fa06a9c8e..1fa068699db38 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -200,6 +200,8 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True, If True, require an exact format match. If False, allow the format to match anywhere in the target string. coerce : force errors to NaT (False by default) + Timestamps outside the interval between Timestamp.min and Timestamp.max + (approximately 1677-09-22 to 2262-04-11) will be also forced to NaT. unit : unit of the arg (D,s,ms,us,ns) denote the unit in epoch (e.g. a unix timestamp), which is an integer/float number infer_datetime_format : boolean, default False @@ -212,6 +214,9 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True, - list-like: DatetimeIndex - Series: Series of datetime64 dtype - scalar: Timestamp + In case when it is not possible to return designated types (e.g. when + any element of input is before Timestamp.min or after Timestamp.max) + return will have datetime.datetime type (or correspoding array/Series). Examples -------- @@ -226,6 +231,11 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True, >>> df = df.astype(str) >>> pd.to_datetime(df.day + df.month + df.year, format="%d%m%Y") + + Date that does not meet timestamp limitations: + + >>> print pd.to_datetime('1300-01-01', format='%Y-%m-%d') + >>> print pd.to_datetime('1300-01-01', format='%Y-%m-%d', coerce=True) """ from pandas import Timestamp from pandas.core.series import Series From 72f4ccb20e44e1e5c5a2387c290dc7725dc9d780 Mon Sep 17 00:00:00 2001 From: Vladimir Filimonov Date: Sun, 4 Jan 2015 22:53:34 +0100 Subject: [PATCH 2/2] Docstring: pd.to_datetime - added output --- pandas/tseries/tools.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index 1fa068699db38..db62fceaceef8 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -226,16 +226,30 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True, >>> i = pd.date_range('20000101',periods=100) >>> df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day)) >>> pd.to_datetime(df.year*10000 + df.month*100 + df.day, format='%Y%m%d') + 0 2000-01-01 + 1 2000-01-02 + ... + 98 2000-04-08 + 99 2000-04-09 + Length: 100, dtype: datetime64[ns] Or from strings >>> df = df.astype(str) >>> pd.to_datetime(df.day + df.month + df.year, format="%d%m%Y") + 0 2000-01-01 + 1 2000-01-02 + ... + 98 2000-04-08 + 99 2000-04-09 + Length: 100, dtype: datetime64[ns] Date that does not meet timestamp limitations: - >>> print pd.to_datetime('1300-01-01', format='%Y-%m-%d') - >>> print pd.to_datetime('1300-01-01', format='%Y-%m-%d', coerce=True) + >>> pd.to_datetime('13000101', format='%Y%m%d') + datetime.datetime(1300, 1, 1, 0, 0) + >>> pd.to_datetime('13000101', format='%Y%m%d', coerce=True) + NaT """ from pandas import Timestamp from pandas.core.series import Series