Skip to content

Commit 7d7c818

Browse files
authored
BUG: TimedeltaArray.astype(duration[{unit}][pyarrow]) (#49795)
* check for np.dtype * whatsnew
1 parent 6a5eb13 commit 7d7c818

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ Conversion
654654
- Bug where any :class:`ExtensionDtype` subclass with ``kind="M"`` would be interpreted as a timezone type (:issue:`34986`)
655655
- Bug in :class:`.arrays.ArrowExtensionArray` that would raise ``NotImplementedError`` when passed a sequence of strings or binary (:issue:`49172`)
656656
- Bug in :func:`to_datetime` was not respecting ``exact`` argument when ``format`` was an ISO8601 format (:issue:`12649`)
657+
- Bug in :meth:`TimedeltaArray.astype` raising ``TypeError`` when converting to a pyarrow duration type (:issue:`49795`)
658+
-
657659

658660
Strings
659661
^^^^^^^

pandas/core/arrays/timedeltas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def astype(self, dtype, copy: bool = True):
332332
# DatetimeLikeArrayMixin super call handles other cases
333333
dtype = pandas_dtype(dtype)
334334

335-
if dtype.kind == "m":
335+
if isinstance(dtype, np.dtype) and dtype.kind == "m":
336336
if dtype == self.dtype:
337337
if copy:
338338
return self.copy()

pandas/tests/extension/test_arrow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,3 +1369,12 @@ def test_pickle_roundtrip(data):
13691369

13701370
result_sliced = pickle.loads(sliced_pickled)
13711371
tm.assert_series_equal(result_sliced, expected_sliced)
1372+
1373+
1374+
def test_astype_from_non_pyarrow(data):
1375+
# GH49795
1376+
pd_array = data._data.to_pandas().array
1377+
result = pd_array.astype(data.dtype)
1378+
assert not isinstance(pd_array.dtype, ArrowDtype)
1379+
assert isinstance(result.dtype, ArrowDtype)
1380+
tm.assert_extension_array_equal(result, data)

0 commit comments

Comments
 (0)