Skip to content

Commit 4445ecd

Browse files
committed
moved logic from algorithms.py to ArrowExtensionArray.map
1 parent 66215a9 commit 4445ecd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pandas/core/algorithms.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
lib,
2525
)
2626
from pandas._libs.missing import NA
27-
from pandas._libs.tslibs.timestamps import Timestamp
2827
from pandas._typing import (
2928
AnyArrayLike,
3029
ArrayLike,
@@ -60,7 +59,6 @@
6059
)
6160
from pandas.core.dtypes.concat import concat_compat
6261
from pandas.core.dtypes.dtypes import (
63-
ArrowDtype,
6462
BaseMaskedDtype,
6563
CategoricalDtype,
6664
ExtensionDtype,
@@ -1693,14 +1691,6 @@ def map_array(
16931691
if na_action == "ignore":
16941692
mapper = mapper[mapper.index.notna()]
16951693

1696-
if isinstance(arr.dtype, ArrowDtype) and arr.dtype.name.startswith("timestamp"):
1697-
try:
1698-
# Convert elements to pandas.Timestamp (or datetime64[ns])
1699-
arr = arr.astype("datetime64[ns]")
1700-
except Exception:
1701-
# fallback: safe, slow path
1702-
arr = np.array([Timestamp(x.as_py()) for x in arr])
1703-
17041694
# Since values were input this means we came from either
17051695
# a dict or a series and mapper should be an index
17061696
indexer = mapper.index.get_indexer(arr)

pandas/core/arrays/arrow/array.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,14 @@ def to_numpy(
14831483
def map(self, mapper, na_action: Literal["ignore"] | None = None):
14841484
if is_numeric_dtype(self.dtype):
14851485
return map_array(self.to_numpy(), mapper, na_action=na_action)
1486+
if self.dtype.name.startswith("timestamp"):
1487+
try:
1488+
# Convert elements to pandas.Timestamp (or datetime64[ns])
1489+
self = self.astype("datetime64[ns]")
1490+
except Exception:
1491+
# fallback: safe, slow path
1492+
self = np.array([Timestamp(x.as_py()) for x in self])
1493+
return map_array(self, mapper, na_action=na_action)
14861494
else:
14871495
return super().map(mapper, na_action)
14881496

0 commit comments

Comments
 (0)