|
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)
|
@@ -3120,17 +3122,28 @@ def _get_lines(self, rows=None):
|
3120 | 3122 | def _make_date_converter(date_parser=None, dayfirst=False,
|
3121 | 3123 | infer_datetime_format=False):
|
3122 | 3124 | def converter(*date_cols):
|
| 3125 | + from pandas.core.dtypes.common import is_datetime64_dtype |
3123 | 3126 | if date_parser is None:
|
3124 | 3127 | strs = _concat_date_cols(date_cols)
|
3125 | 3128 |
|
3126 | 3129 | try:
|
3127 |
| - return tools.to_datetime( |
| 3130 | + dti = tools.to_datetime( |
3128 | 3131 | ensure_object(strs),
|
3129 | 3132 | utc=None,
|
3130 | 3133 | dayfirst=dayfirst,
|
3131 | 3134 | errors='ignore',
|
3132 | 3135 | infer_datetime_format=infer_datetime_format
|
3133 | 3136 | )
|
| 3137 | + |
| 3138 | + if isinstance(dti, DatetimeIndex): |
| 3139 | + dti = dti.to_pydatetime() |
| 3140 | + elif is_datetime64_dtype(dti): |
| 3141 | + dti = np.array([Timestamp(ts).to_pydatetime() |
| 3142 | + for ts in dti]) |
| 3143 | + else: |
| 3144 | + dti = dti.to_numpy() |
| 3145 | + |
| 3146 | + return dti |
3134 | 3147 | except ValueError:
|
3135 | 3148 | return tools.to_datetime(
|
3136 | 3149 | parsing.try_parse_dates(strs, dayfirst=dayfirst))
|
|
0 commit comments