Skip to content

Commit c168883

Browse files
authored
PERF: Avoid a numpy array copy in ArrowExtensionArray._to_datetimearray (#60778)
1 parent 0c4ca3a commit c168883

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pandas/core/arrays/arrow/array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ def _to_datetimearray(self) -> DatetimeArray:
13981398
np_dtype = np.dtype(f"M8[{pa_type.unit}]")
13991399
dtype = tz_to_dtype(pa_type.tz, pa_type.unit)
14001400
np_array = self._pa_array.to_numpy()
1401-
np_array = np_array.astype(np_dtype)
1401+
np_array = np_array.astype(np_dtype, copy=False)
14021402
return DatetimeArray._simple_new(np_array, dtype=dtype)
14031403

14041404
def _to_timedeltaarray(self) -> TimedeltaArray:
@@ -1409,7 +1409,7 @@ def _to_timedeltaarray(self) -> TimedeltaArray:
14091409
assert pa.types.is_duration(pa_type)
14101410
np_dtype = np.dtype(f"m8[{pa_type.unit}]")
14111411
np_array = self._pa_array.to_numpy()
1412-
np_array = np_array.astype(np_dtype)
1412+
np_array = np_array.astype(np_dtype, copy=False)
14131413
return TimedeltaArray._simple_new(np_array, dtype=np_dtype)
14141414

14151415
def _values_for_json(self) -> np.ndarray:

0 commit comments

Comments
 (0)