Skip to content

Commit

Permalink
PERF: Avoid a numpy array copy in ArrowExtensionArray._to_datetimearr…
Browse files Browse the repository at this point in the history
…ay (#60778)
  • Loading branch information
mroeschke authored Jan 24, 2025
1 parent 0c4ca3a commit c168883
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ def _to_datetimearray(self) -> DatetimeArray:
np_dtype = np.dtype(f"M8[{pa_type.unit}]")
dtype = tz_to_dtype(pa_type.tz, pa_type.unit)
np_array = self._pa_array.to_numpy()
np_array = np_array.astype(np_dtype)
np_array = np_array.astype(np_dtype, copy=False)
return DatetimeArray._simple_new(np_array, dtype=dtype)

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

def _values_for_json(self) -> np.ndarray:
Expand Down

0 comments on commit c168883

Please sign in to comment.