Skip to content

Commit 1c55a7f

Browse files
committed
Fix pandas-dev#60766:.map,.apply would convert element type for extension array.
1 parent b64f438 commit 1c55a7f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ def max(self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs):
13251325
return self._wrap_reduction_result("max", result, skipna=skipna, axis=axis)
13261326

13271327
def map(self, mapper, na_action: Literal["ignore"] | None = None):
1328-
return map_array(self.to_numpy(), mapper, na_action=na_action)
1328+
return map_array(self, mapper, na_action=na_action)
13291329

13301330
@overload
13311331
def any(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pandas as pd
2+
3+
def test_basemaskedarray_map():
4+
for dtype, data, expected_data in [
5+
("Int32", [1, 2, None, 4], [2, 3, pd.NA, 5]),
6+
7+
]:
8+
s = pd.Series(data, dtype=dtype)
9+
10+
def transform(x):
11+
if x is None:
12+
return x
13+
return x + 1
14+
15+
result = s.map(transform)
16+
expected = pd.Series(expected_data, dtype=result.dtype)
17+
18+
assert result.tolist() == expected.tolist()

0 commit comments

Comments
 (0)