|
99 | 99 | from pandas import Series |
100 | 100 | from pandas.core.arrays import ExtensionArray |
101 | 101 | from pandas.core.indexes.base import Index |
102 | | - from pandas.core.indexes.datetimes import DatetimeIndex |
103 | 102 |
|
104 | 103 | _int8_max = np.iinfo(np.int8).max |
105 | 104 | _int16_max = np.iinfo(np.int16).max |
@@ -1121,57 +1120,6 @@ def astype_nansafe( |
1121 | 1120 | return arr.view(dtype) |
1122 | 1121 |
|
1123 | 1122 |
|
1124 | | -def maybe_convert_objects( |
1125 | | - values: np.ndarray, convert_numeric: bool = True |
1126 | | -) -> Union[np.ndarray, "DatetimeIndex"]: |
1127 | | - """ |
1128 | | - If we have an object dtype array, try to coerce dates and/or numbers. |
1129 | | -
|
1130 | | - Parameters |
1131 | | - ---------- |
1132 | | - values : ndarray |
1133 | | - convert_numeric : bool, default True |
1134 | | -
|
1135 | | - Returns |
1136 | | - ------- |
1137 | | - ndarray or DatetimeIndex |
1138 | | - """ |
1139 | | - validate_bool_kwarg(convert_numeric, "convert_numeric") |
1140 | | - |
1141 | | - orig_values = values |
1142 | | - |
1143 | | - # convert dates |
1144 | | - if is_object_dtype(values.dtype): |
1145 | | - values = lib.maybe_convert_objects(values, convert_datetime=True) |
1146 | | - |
1147 | | - # convert timedeltas |
1148 | | - if is_object_dtype(values.dtype): |
1149 | | - values = lib.maybe_convert_objects(values, convert_timedelta=True) |
1150 | | - |
1151 | | - # convert to numeric |
1152 | | - if is_object_dtype(values.dtype): |
1153 | | - if convert_numeric: |
1154 | | - try: |
1155 | | - new_values = lib.maybe_convert_numeric( |
1156 | | - values, set(), coerce_numeric=True |
1157 | | - ) |
1158 | | - except (ValueError, TypeError): |
1159 | | - pass |
1160 | | - else: |
1161 | | - # if we are all nans then leave me alone |
1162 | | - if not isna(new_values).all(): |
1163 | | - values = new_values |
1164 | | - |
1165 | | - else: |
1166 | | - # soft-conversion |
1167 | | - values = lib.maybe_convert_objects(values) |
1168 | | - |
1169 | | - if values is orig_values: |
1170 | | - values = values.copy() |
1171 | | - |
1172 | | - return values |
1173 | | - |
1174 | | - |
1175 | 1123 | def soft_convert_objects( |
1176 | 1124 | values: np.ndarray, |
1177 | 1125 | datetime: bool = True, |
|
0 commit comments