Skip to content

TST: Check map function works with StringDtype (#40823) #41723

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

Merged
merged 6 commits into from
Jun 2, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pandas/tests/frame/methods/test_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pandas as pd
import pandas._testing as tm


class TestMap:
Copy link
Contributor

Choose a reason for hiding this comment

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

we have extensive map tests here: pandas/tests/apply/test_series_apply.py

see if you can find something similar. you can use the fixture any_string_dtype to parmeterize this over various kinds of strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok moved. Should the fixture be used like this?

# parameter
test_series_map_stringdtype(any_string_dtype):
    ser1 = Series(
        # ...
        # then set here for all Series
        dtype=any_string_dtype,
    )

def test_map(self):
# map test on StringDType, GH#40823
df1 = pd.DataFrame(
{"col1": [pd.NA, "foo", "bar"]},
index=["id1", "id2", "id3"],
dtype=pd.StringDtype(),
)

df2 = pd.DataFrame({"id": ["id4", "id2", "id1"]}, dtype=pd.StringDtype())

df2["col1"] = df2["id"].map(df1["col1"])

result = df2
expected = pd.DataFrame(
{"id": ["id4", "id2", "id1"], "col1": [pd.NA, "foo", pd.NA]},
dtype=pd.StringDtype(),
)

tm.assert_frame_equal(result, expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a series method, so test on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, updated the test.