|
14 | 14 |
|
15 | 15 | import numpy as np
|
16 | 16 |
|
| 17 | +from pandas import DatetimeIndex |
| 18 | + |
17 | 19 | import pandas._libs.lib as lib
|
18 | 20 | import pandas._libs.ops as libops
|
19 | 21 | import pandas._libs.parsers as parsers
|
20 |
| -from pandas._libs.tslibs import parsing |
| 22 | +from pandas._libs.tslibs import parsing, Timestamp |
21 | 23 | import pandas.compat as compat
|
22 | 24 | from pandas.compat import (
|
23 | 25 | PY3, StringIO, lrange, lzip, map, range, string_types, u, zip)
|
@@ -3139,17 +3141,28 @@ def _get_lines(self, rows=None):
|
3139 | 3141 | def _make_date_converter(date_parser=None, dayfirst=False,
|
3140 | 3142 | infer_datetime_format=False):
|
3141 | 3143 | def converter(*date_cols):
|
| 3144 | + from pandas.core.dtypes.common import is_datetime64_dtype |
3142 | 3145 | if date_parser is None:
|
3143 | 3146 | strs = _concat_date_cols(date_cols)
|
3144 | 3147 |
|
3145 | 3148 | try:
|
3146 |
| - return tools.to_datetime( |
| 3149 | + dti = tools.to_datetime( |
3147 | 3150 | ensure_object(strs),
|
3148 | 3151 | utc=None,
|
3149 | 3152 | dayfirst=dayfirst,
|
3150 | 3153 | errors='ignore',
|
3151 | 3154 | infer_datetime_format=infer_datetime_format
|
3152 | 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() |
| 3164 | + |
| 3165 | + return dti |
3153 | 3166 | except ValueError:
|
3154 | 3167 | return tools.to_datetime(
|
3155 | 3168 | parsing.try_parse_dates(strs, dayfirst=dayfirst))
|
|
0 commit comments