From 78b92c4ef03d6be0bfa8b46d69fb9c3c60c55e69 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Fri, 13 Jun 2025 17:22:08 +0800 Subject: [PATCH 1/2] call self.to_numpy() when self.dtype.pyarrow_dtype is datelike --- pandas/core/arrays/arrow/array.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 0b90bcea35100..76b6bd01fc24f 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -1480,6 +1480,10 @@ def to_numpy( def map(self, mapper, na_action: Literal["ignore"] | None = None): if is_numeric_dtype(self.dtype): return map_array(self.to_numpy(), mapper, na_action=na_action) + elif pa.types.is_date(self.dtype.pyarrow_dtype) or pa.types.is_timestamp( + self.dtype.pyarrow_dtype + ): + return map_array(self.to_numpy(), mapper, na_action=na_action) else: return super().map(mapper, na_action) From ffb2a6f358fcb94d1922367756502947e4dab685 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Fri, 13 Jun 2025 17:25:05 +0800 Subject: [PATCH 2/2] refactor to combine in one if block --- pandas/core/arrays/arrow/array.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 76b6bd01fc24f..ecd3fdb4dc8bc 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -1478,10 +1478,10 @@ def to_numpy( return result def map(self, mapper, na_action: Literal["ignore"] | None = None): - if is_numeric_dtype(self.dtype): - return map_array(self.to_numpy(), mapper, na_action=na_action) - elif pa.types.is_date(self.dtype.pyarrow_dtype) or pa.types.is_timestamp( - self.dtype.pyarrow_dtype + if ( + is_numeric_dtype(self.dtype) + or pa.types.is_date(self.dtype.pyarrow_dtype) + or pa.types.is_timestamp(self.dtype.pyarrow_dtype) ): return map_array(self.to_numpy(), mapper, na_action=na_action) else: