Skip to content

Commit b59d6b8

Browse files
committed
TST: Check map function works with StringDType (pandas-dev#40823).
1 parent 671cf86 commit b59d6b8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import numpy as np
2+
import pytest
3+
4+
import pandas as pd
5+
import pandas._testing as tm
6+
7+
8+
class TestMap:
9+
def test_map(self):
10+
# map test on StringDType, GH#40823
11+
df1 = pd.DataFrame(
12+
{
13+
"col1": [pd.NA, "foo", "bar"]
14+
}, index=["id1", "id2", "id3"], dtype=pd.StringDtype()
15+
)
16+
17+
df2 = pd.DataFrame(
18+
{
19+
"id": ["id4", "id2", "id1"]
20+
}, dtype=pd.StringDtype()
21+
)
22+
23+
df2["col1"] = df2["id"].map(df1["col1"])
24+
25+
result = df2
26+
expected = pd.DataFrame(
27+
{
28+
"id": ["id4", "id2", "id1"],
29+
"col1": [pd.NA, "foo", pd.NA]
30+
}, dtype=pd.StringDtype()
31+
)
32+
33+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)