|
23 | 23 | from pandas.util._exceptions import find_stack_level |
24 | 24 |
|
25 | 25 | from pandas.core.dtypes.common import is_list_like |
| 26 | +from pandas.core.dtypes.dtypes import ArrowDtype |
26 | 27 | from pandas.core.dtypes.generic import ( |
27 | 28 | ABCIndex, |
28 | 29 | ABCSeries, |
|
31 | 32 | from pandas.core.arrays.timedeltas import sequence_to_td64ns |
32 | 33 |
|
33 | 34 | if TYPE_CHECKING: |
| 35 | + from collections.abc import Hashable |
34 | 36 | from datetime import timedelta |
35 | 37 |
|
36 | 38 | from pandas._libs.tslibs.timedeltas import UnitChoices |
@@ -242,17 +244,23 @@ def _coerce_scalar_to_timedelta_type( |
242 | 244 |
|
243 | 245 |
|
244 | 246 | def _convert_listlike( |
245 | | - arg, unit=None, errors: DateTimeErrorChoices = "raise", name=None |
| 247 | + arg, |
| 248 | + unit: UnitChoices | None = None, |
| 249 | + errors: DateTimeErrorChoices = "raise", |
| 250 | + name: Hashable | None = None, |
246 | 251 | ): |
247 | 252 | """Convert a list of objects to a timedelta index object.""" |
248 | | - if isinstance(arg, (list, tuple)) or not hasattr(arg, "dtype"): |
| 253 | + arg_dtype = getattr(arg, "dtype", None) |
| 254 | + if isinstance(arg, (list, tuple)) or arg_dtype is None: |
249 | 255 | # This is needed only to ensure that in the case where we end up |
250 | 256 | # returning arg (errors == "ignore"), and where the input is a |
251 | 257 | # generator, we return a useful list-like instead of a |
252 | 258 | # used-up generator |
253 | 259 | if not hasattr(arg, "__array__"): |
254 | 260 | arg = list(arg) |
255 | 261 | arg = np.array(arg, dtype=object) |
| 262 | + elif isinstance(arg_dtype, ArrowDtype) and arg_dtype.kind == "m": |
| 263 | + return arg |
256 | 264 |
|
257 | 265 | try: |
258 | 266 | td64arr = sequence_to_td64ns(arg, unit=unit, errors=errors, copy=False)[0] |
|
0 commit comments