|
25 | 25 | from pandas.core.dtypes.missing import isna |
26 | 26 | from pandas.core.dtypes.cast import astype_nansafe |
27 | 27 | from pandas.core.index import (Index, MultiIndex, RangeIndex, |
28 | | - ensure_index_from_sequences) |
| 28 | + ensure_index_from_sequences, |
| 29 | + DatetimeIndex) |
29 | 30 | from pandas.core.series import Series |
30 | 31 | from pandas.core.frame import DataFrame |
31 | 32 | from pandas.core.arrays import Categorical |
@@ -1589,11 +1590,13 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False, |
1589 | 1590 | else: |
1590 | 1591 | # skip inference if specified dtype is object |
1591 | 1592 | try_num_bool = not (cast_type and is_string_dtype(cast_type)) |
1592 | | - |
1593 | | - # general type inference and conversion |
1594 | | - cvals, na_count = self._infer_types( |
1595 | | - values, set(col_na_values) | col_na_fvalues, |
1596 | | - try_num_bool) |
| 1593 | + if isinstance(values, np.ndarray): |
| 1594 | + # general type inference and conversion |
| 1595 | + cvals, na_count = self._infer_types( |
| 1596 | + values, set(col_na_values) | col_na_fvalues, |
| 1597 | + try_num_bool) |
| 1598 | + else: # _infer_types only accepts ndarray. |
| 1599 | + cvals = values |
1597 | 1600 |
|
1598 | 1601 | # type specified in dtype param |
1599 | 1602 | if cast_type and not is_dtype_equal(cvals, cast_type): |
@@ -3030,14 +3033,19 @@ def converter(*date_cols): |
3030 | 3033 | strs = _concat_date_cols(date_cols) |
3031 | 3034 |
|
3032 | 3035 | try: |
3033 | | - return tools.to_datetime( |
| 3036 | + converted = tools.to_datetime( |
3034 | 3037 | ensure_object(strs), |
3035 | 3038 | utc=None, |
3036 | | - box=False, |
| 3039 | + box=True, |
3037 | 3040 | dayfirst=dayfirst, |
3038 | 3041 | errors='ignore', |
3039 | 3042 | infer_datetime_format=infer_datetime_format |
3040 | 3043 | ) |
| 3044 | + if not isinstance(converted, DatetimeIndex): |
| 3045 | + # GH-22256 : non-datetime Index needs to be |
| 3046 | + # converted to ndarray to avoid downstream errors |
| 3047 | + return np.array(converted) |
| 3048 | + return converted |
3041 | 3049 | except: |
3042 | 3050 | return tools.to_datetime( |
3043 | 3051 | parsing.try_parse_dates(strs, dayfirst=dayfirst)) |
|
0 commit comments