Skip to content

Commit 61452ac

Browse files
committed
Added changes and new test file
1 parent 780d48c commit 61452ac

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

pandas/core/algorithms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,11 +1703,11 @@ def mapper_check(x):
17031703
if x is None:
17041704
return pd.NA
17051705
else:
1706-
mapper(x)
1706+
return mapper(x)
17071707
values = arr.copy()
17081708

17091709
if na_action is None:
17101710
#return lib.map_infer(values, mapper)
1711-
return np.array([mapper_check(x) for x in values], dtype = arr.dtype)
1711+
return pd.array([mapper_check(x) for x in values], dtype = arr.dtype)
17121712
else:
17131713
return lib.map_infer_mask(values, mapper, mask=isna(values).view(np.uint8))

pandas/core/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4626,7 +4626,7 @@ def apply_check(val):
46264626
if val is None:
46274627
return pd.NA
46284628
return val
4629-
func = functools.partial(apply_check,func)
4629+
self = [apply_check(x) for x in self]
46304630

46314631
#proceed with usual apply method
46324632
return SeriesApply(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import numpy as np
2+
import pytest
3+
4+
import pandas as pd
5+
from pandas import (
6+
DataFrame,
7+
Index,
8+
MultiIndex,
9+
Series,
10+
concat,
11+
date_range,
12+
timedelta_range,
13+
)
14+
import pandas._testing as tm
15+
from pandas.tests.apply.common import series_transform_kernels
16+
17+
def test_series_map_NAinteger():
18+
s = pd.Series([1,2,None],dtype="Int32")
19+
20+
def increment(x):
21+
if x is None:
22+
return pd.NA
23+
return x+1
24+
25+
26+
result = s.map(increment)
27+
28+
expectedResult = pd.Series([2,3,pd.NA],dtype = "Int32")
29+
30+
pd.testing.assert_series_equal(result,expectedResult)
31+
32+
def test_series_apply_NAinteger():
33+
s = pd.Series([1,2,None],dtype="Int32")
34+
35+
def increment(x):
36+
if x is None:
37+
return pd.NA
38+
return x+1
39+
40+
41+
result = s.apply(increment)
42+
43+
expectedResult = pd.Series([2,3,pd.NA],dtype = "Int32")
44+
45+
pd.testing.assert_series_equal(result,expectedResult)

0 commit comments

Comments
 (0)