Skip to content

Commit 4f712c1

Browse files
authored
PERF: TimedeltaArray.astype(object) (pandas-dev#45571)
1 parent e2b7c34 commit 4f712c1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pandas/core/arrays/datetimelike.py

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
delta_to_nanoseconds,
3838
iNaT,
3939
ints_to_pydatetime,
40+
ints_to_pytimedelta,
4041
to_offset,
4142
)
4243
from pandas._libs.tslibs.fields import (
@@ -421,6 +422,11 @@ def astype(self, dtype, copy: bool = True):
421422
)
422423
return converted.reshape(self.shape)
423424

425+
elif self.dtype.kind == "m":
426+
i8data = self.asi8.ravel()
427+
converted = ints_to_pytimedelta(i8data, box=True)
428+
return converted.reshape(self.shape)
429+
424430
return self._box_values(self.asi8.ravel()).reshape(self.shape)
425431

426432
elif isinstance(dtype, ExtensionDtype):

0 commit comments

Comments
 (0)