In [46]: pd.__version__
Out[46]: '0.25.0.dev0+593.g307265e28'
In [47]: pd.to_datetime(['15010101', '20150101', np.nan], format="%Y%m%d", errors='ignore')
Out[47]: DatetimeIndex(['2085-07-20 23:34:33.709551616', '2015-01-01 00:00:00', 'NaT'], dtype='datetime64[ns]', freq=None)
Comment From: makbigc
https://github.com/pandas-dev/pandas/blob/ba48fc4a033f11513fa2dd44c946e18b7bc27ad2/pandas/core/tools/datetimes.py#L772
The astype
conversion turns all elements no matter the element is out of bound.
Comment From: jorisvandenbossche
I can't say for sure (without looking more in detail) if that is indeed the reason (I would think that the array_to_datetime
in the calc
function a just above should still raise for out of bounds datetimes). But welcome to check further! Eg does it work correctly if you leave out the astype?
Comment From: another-green
What is the expected behavior of to_datetime in this case? If there is time out of bound, should it just ignore all the elements in the array and return an Index? For example:
Index(['15010101', '20150101', nan], dtype='object')
Or we want to convert the date like element, such as
Index([1501-01-01 00:00:00, 2015-01-01 00:00:00, 'NaT'], dtype='object')
Comment From: jorisvandenbossche
That's not fully clear. See also https://github.com/pandas-dev/pandas/issues/14487
Comment From: MarcoGorelli
this'll be addressed by https://github.com/pandas-dev/pandas/pull/50242