Skip to content

BUG: Add PyArrow datelike type support for map() #61644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 2 additions & 3 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,10 +1490,9 @@ def to_numpy(
return result

def map(self, mapper, na_action: Literal["ignore"] | None = None):
if is_numeric_dtype(self.dtype):
if self.dtype.kind in "mM" or is_numeric_dtype(self.dtype):
return map_array(self.to_numpy(), mapper, na_action=na_action)
else:
return super().map(mapper, na_action)
return super().map(mapper, na_action)

@doc(ExtensionArray.duplicated)
def duplicated(
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
is_string_dtype,
is_unsigned_integer_dtype,
)
from pandas.core.algorithms import map_array
from pandas.tests.extension import base

pa = pytest.importorskip("pyarrow")
Expand Down Expand Up @@ -278,8 +279,9 @@ def test_compare_scalar(self, data, comparison_op):
@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data_missing, na_action):
if data_missing.dtype.kind in "mM":
result = data_missing.map(lambda x: x, na_action=na_action)
expected = data_missing.to_numpy(dtype=object)
mapper = lambda x: x
result = data_missing.map(mapper, na_action=na_action)
expected = map_array(data_missing.to_numpy(), mapper, na_action=na_action)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is map_array necessary here? seems like this should be correct without it

tm.assert_numpy_array_equal(result, expected)
else:
result = data_missing.map(lambda x: x, na_action=na_action)
Expand Down
Loading