Skip to content

Commit 6f108dd

Browse files
committed
avoid double-copy
1 parent e41068a commit 6f108dd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pandas/core/arrays/timedeltas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,14 @@ def astype(self, dtype, copy=True):
243243
# by pandas convention, converting to non-nano timedelta64
244244
# returns an int64-dtyped array with ints representing multiples
245245
# of the desired timedelta unit. This is essentially division
246-
result = self._data.astype(dtype, copy=copy)
247246
if self._hasnans:
247+
# avoid double-copying
248+
result = self._data.astype(dtype, copy=False)
248249
values = self._maybe_mask_results(result,
249250
fill_value=None,
250251
convert='float64')
251252
return values
253+
result = self._data.astype(dtype, copy=copy)
252254
return result.astype('i8')
253255
elif is_timedelta64_ns_dtype(dtype):
254256
if copy:

0 commit comments

Comments
 (0)