|
26 | 26 | )
|
27 | 27 | import warnings
|
28 | 28 |
|
| 29 | +from dateutil.parser import ParserError |
29 | 30 | import numpy as np
|
30 | 31 |
|
31 | 32 | from pandas._libs import (
|
@@ -1315,11 +1316,7 @@ def convert_dtypes(
|
1315 | 1316 | if (
|
1316 | 1317 | convert_string or convert_integer or convert_boolean or convert_floating
|
1317 | 1318 | ) and not is_extension:
|
1318 |
| - try: |
1319 |
| - inferred_dtype = lib.infer_dtype(input_array) |
1320 |
| - except ValueError: |
1321 |
| - # Required to catch due to Period. Can remove once GH 23553 is fixed |
1322 |
| - inferred_dtype = input_array.dtype |
| 1319 | + inferred_dtype = lib.infer_dtype(input_array) |
1323 | 1320 |
|
1324 | 1321 | if not convert_string and is_string_dtype(inferred_dtype):
|
1325 | 1322 | inferred_dtype = input_array.dtype
|
@@ -1591,8 +1588,19 @@ def maybe_cast_to_datetime(
|
1591 | 1588 | value = to_timedelta(value, errors="raise")._values
|
1592 | 1589 | except OutOfBoundsDatetime:
|
1593 | 1590 | raise
|
1594 |
| - except (ValueError, TypeError): |
| 1591 | + except ParserError: |
| 1592 | + # Note: ParserError subclasses ValueError |
| 1593 | + # str that we can't parse to datetime |
1595 | 1594 | pass
|
| 1595 | + except ValueError as err: |
| 1596 | + if "mixed datetimes and integers in passed array" in str(err): |
| 1597 | + # array_to_datetime does not allow this; |
| 1598 | + # when called from _try_cast, this will be followed |
| 1599 | + # by a call to construct_1d_ndarray_preserving_na |
| 1600 | + # which will convert these |
| 1601 | + pass |
| 1602 | + else: |
| 1603 | + raise |
1596 | 1604 |
|
1597 | 1605 | # coerce datetimelike to object
|
1598 | 1606 | elif is_datetime64_dtype(
|
|
0 commit comments