@@ -200,6 +200,8 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
200
200
If True, require an exact format match.
201
201
If False, allow the format to match anywhere in the target string.
202
202
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.
203
205
unit : unit of the arg (D,s,ms,us,ns) denote the unit in epoch
204
206
(e.g. a unix timestamp), which is an integer/float number
205
207
infer_datetime_format : boolean, default False
@@ -212,6 +214,9 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
212
214
- list-like: DatetimeIndex
213
215
- Series: Series of datetime64 dtype
214
216
- 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).
215
220
216
221
Examples
217
222
--------
@@ -221,11 +226,30 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
221
226
>>> i = pd.date_range('20000101',periods=100)
222
227
>>> df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
223
228
>>> 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]
224
235
225
236
Or from strings
226
237
227
238
>>> df = df.astype(str)
228
239
>>> 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
229
253
"""
230
254
from pandas import Timestamp
231
255
from pandas .core .series import Series
0 commit comments