Skip to content

Commit 05f59dd

Browse files
committed
Merge pull request #9189 from vfilimonov/doc_to_datetime
Docstring: pd.to_datetime (issue #9107)
2 parents b3d1a05 + 72f4ccb commit 05f59dd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tseries/tools.py

+24
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
200200
If True, require an exact format match.
201201
If False, allow the format to match anywhere in the target string.
202202
coerce : force errors to NaT (False by default)
203+
Timestamps outside the interval between Timestamp.min and Timestamp.max
204+
(approximately 1677-09-22 to 2262-04-11) will be also forced to NaT.
203205
unit : unit of the arg (D,s,ms,us,ns) denote the unit in epoch
204206
(e.g. a unix timestamp), which is an integer/float number
205207
infer_datetime_format : boolean, default False
@@ -212,6 +214,9 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
212214
- list-like: DatetimeIndex
213215
- Series: Series of datetime64 dtype
214216
- scalar: Timestamp
217+
In case when it is not possible to return designated types (e.g. when
218+
any element of input is before Timestamp.min or after Timestamp.max)
219+
return will have datetime.datetime type (or correspoding array/Series).
215220
216221
Examples
217222
--------
@@ -221,11 +226,30 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
221226
>>> i = pd.date_range('20000101',periods=100)
222227
>>> df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
223228
>>> pd.to_datetime(df.year*10000 + df.month*100 + df.day, format='%Y%m%d')
229+
0 2000-01-01
230+
1 2000-01-02
231+
...
232+
98 2000-04-08
233+
99 2000-04-09
234+
Length: 100, dtype: datetime64[ns]
224235
225236
Or from strings
226237
227238
>>> df = df.astype(str)
228239
>>> pd.to_datetime(df.day + df.month + df.year, format="%d%m%Y")
240+
0 2000-01-01
241+
1 2000-01-02
242+
...
243+
98 2000-04-08
244+
99 2000-04-09
245+
Length: 100, dtype: datetime64[ns]
246+
247+
Date that does not meet timestamp limitations:
248+
249+
>>> pd.to_datetime('13000101', format='%Y%m%d')
250+
datetime.datetime(1300, 1, 1, 0, 0)
251+
>>> pd.to_datetime('13000101', format='%Y%m%d', coerce=True)
252+
NaT
229253
"""
230254
from pandas import Timestamp
231255
from pandas.core.series import Series

0 commit comments

Comments
 (0)