MCPcopy
hub / github.com/pandas-dev/pandas / _to_datetimearray

Method _to_datetimearray

pandas/core/arrays/arrow/array.py:1669–1682  ·  view source on GitHub ↗

Convert a pyarrow timestamp typed array to a DatetimeArray.

(self)

Source from the content-addressed store, hash-verified

1667 return self
1668
1669 def _to_datetimearray(self) -> DatetimeArray:
1670 """Convert a pyarrow timestamp typed array to a DatetimeArray."""
1671 from pandas.core.arrays.datetimes import (
1672 DatetimeArray,
1673 tz_to_dtype,
1674 )
1675
1676 pa_type = self._pa_array.type
1677 assert pa.types.is_timestamp(pa_type)
1678 np_dtype = np.dtype(f"M8[{pa_type.unit}]")
1679 dtype = tz_to_dtype(pa_type.tz, pa_type.unit)
1680 np_array = self._pa_array.to_numpy()
1681 np_array = np_array.astype(np_dtype, copy=False)
1682 return DatetimeArray._simple_new(np_array, dtype=dtype)
1683
1684 def _to_timedeltaarray(self) -> TimedeltaArray:
1685 """Convert a pyarrow duration typed array to a TimedeltaArray."""

Callers 5

_groupby_opMethod · 0.95
infer_freqFunction · 0.80
_engineMethod · 0.80
_get_engine_targetMethod · 0.80

Calls 5

tz_to_dtypeFunction · 0.90
dtypeMethod · 0.45
to_numpyMethod · 0.45
astypeMethod · 0.45
_simple_newMethod · 0.45

Tested by

no test coverage detected