Skip to content

Commit 2f81938

Browse files
author
Chris Bertinato
committed
Fix
1 parent 20be993 commit 2f81938

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

pandas/io/parsers.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -3141,28 +3141,18 @@ def _get_lines(self, rows=None):
31413141
def _make_date_converter(date_parser=None, dayfirst=False,
31423142
infer_datetime_format=False):
31433143
def converter(*date_cols):
3144-
from pandas.core.dtypes.common import is_datetime64_dtype
31453144
if date_parser is None:
31463145
strs = _concat_date_cols(date_cols)
31473146

31483147
try:
3149-
dti = tools.to_datetime(
3148+
return tools.to_datetime(
31503149
ensure_object(strs),
31513150
utc=None,
31523151
dayfirst=dayfirst,
31533152
errors='ignore',
31543153
infer_datetime_format=infer_datetime_format
3155-
)
3156-
3157-
if isinstance(dti, DatetimeIndex):
3158-
dti = dti.to_pydatetime()
3159-
# elif is_datetime64_dtype(dti):
3160-
# dti = np.array([Timestamp(ts).to_pydatetime()
3161-
# for ts in dti])
3162-
else:
3163-
dti = dti.to_numpy()
3154+
).to_numpy()
31643155

3165-
return dti
31663156
except ValueError:
31673157
return tools.to_datetime(
31683158
parsing.try_parse_dates(strs, dayfirst=dayfirst))

pandas/tests/indexes/datetimes/test_tools.py

+32-36
Original file line numberDiff line numberDiff line change
@@ -358,47 +358,43 @@ def test_to_datetime_dt64s(self, cache):
358358
def test_to_datetime_array_of_dt64s(self, cache):
359359
dts = [np.datetime64('2000-01-01'), np.datetime64('2000-01-02'), ]
360360

361-
with tm.assert_produces_warning(FutureWarning):
362-
363-
# Assuming all datetimes are in bounds, to_datetime() returns
364-
# an array that is equal to Timestamp() parsing
365-
tm.assert_numpy_array_equal(
366-
pd.to_datetime(dts, box=False, cache=cache),
367-
np.array([Timestamp(x).asm8 for x in dts])
368-
)
361+
# Assuming all datetimes are in bounds, to_datetime() returns
362+
# an array that is equal to Timestamp() parsing
363+
tm.assert_numpy_array_equal(
364+
pd.to_datetime(dts, cache=cache).to_numpy(),
365+
np.array([Timestamp(x).asm8 for x in dts])
366+
)
369367

370-
# A list of datetimes where the last one is out of bounds
371-
dts_with_oob = dts + [np.datetime64('9999-01-01')]
368+
# A list of datetimes where the last one is out of bounds
369+
dts_with_oob = dts + [np.datetime64('9999-01-01')]
372370

373-
pytest.raises(ValueError, pd.to_datetime, dts_with_oob,
374-
errors='raise')
371+
with pytest.raises(ValueError):
372+
pd.to_datetime(dts_with_oob)
375373

376-
with tm.assert_produces_warning(FutureWarning):
377-
tm.assert_numpy_array_equal(
378-
pd.to_datetime(dts_with_oob, box=False, errors='coerce',
379-
cache=cache),
380-
np.array(
381-
[
382-
Timestamp(dts_with_oob[0]).asm8,
383-
Timestamp(dts_with_oob[1]).asm8,
384-
tslib.iNaT,
385-
],
386-
dtype='M8'
387-
)
374+
tm.assert_numpy_array_equal(
375+
pd.to_datetime(dts_with_oob, errors='coerce',
376+
cache=cache).to_numpy(),
377+
np.array(
378+
[
379+
Timestamp(dts_with_oob[0]).asm8,
380+
Timestamp(dts_with_oob[1]).asm8,
381+
tslib.iNaT,
382+
],
383+
dtype='M8'
388384
)
389-
390-
with tm.assert_produces_warning(FutureWarning):
391-
# With errors='ignore', out of bounds datetime64s
392-
# are converted to their .item(), which depending on the version of
393-
# numpy is either a python datetime.datetime or datetime.date
394-
tm.assert_numpy_array_equal(
395-
pd.to_datetime(dts_with_oob, box=False, errors='ignore',
396-
cache=cache),
397-
np.array(
398-
[dt.item() for dt in dts_with_oob],
399-
dtype='O'
400-
)
385+
)
386+
387+
# With errors='ignore', out of bounds datetime64s
388+
# are converted to their .item(), which depending on the version of
389+
# numpy is either a python datetime.datetime or datetime.date
390+
tm.assert_numpy_array_equal(
391+
pd.to_datetime(dts_with_oob, errors='ignore',
392+
cache=cache).to_numpy(),
393+
np.array(
394+
[dt.item() for dt in dts_with_oob],
395+
dtype='O'
401396
)
397+
)
402398

403399
@pytest.mark.parametrize('cache', [True, False])
404400
def test_to_datetime_tz(self, cache):

0 commit comments

Comments
 (0)