-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
differences in Series.map with defaultdict with different dtypes #49011
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
Changes from all commits
138c298
a42c9dd
e15a9eb
35a30f9
3c2dddb
6a43c79
b618938
7fc199c
31b69e9
6a8efb8
349d54f
ee788c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -598,6 +598,36 @@ def test_map_dict_na_key(): | |
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("na_action", [None, "ignore"]) | ||
def test_map_defaultdict_na_key(na_action): | ||
# GH 48813 | ||
s = Series([1, 2, np.nan]) | ||
default_map = defaultdict(lambda: "missing", {1: "a", 2: "b", np.nan: "c"}) | ||
result = s.map(default_map, na_action=na_action) | ||
expected = Series({0: "a", 1: "b", 2: "c" if na_action is None else np.nan}) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("na_action", [None, "ignore"]) | ||
def test_map_defaultdict_missing_key(na_action): | ||
# GH 48813 | ||
s = Series([1, 2, np.nan]) | ||
default_map = defaultdict(lambda: "missing", {1: "a", 2: "b", 3: "c"}) | ||
result = s.map(default_map, na_action=na_action) | ||
expected = Series({0: "a", 1: "b", 2: "missing" if na_action is None else np.nan}) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("na_action", [None, "ignore"]) | ||
def test_map_defaultdict_unmutated(na_action): | ||
# GH 48813 | ||
s = Series([1, 2, np.nan]) | ||
default_map = defaultdict(lambda: "missing", {1: "a", 2: "b", np.nan: "c"}) | ||
expected_default_map = default_map.copy() | ||
s.map(default_map, na_action=na_action) | ||
assert default_map == expected_default_map | ||
|
||
|
||
@pytest.mark.parametrize("arg_func", [dict, Series]) | ||
def test_map_dict_ignore_na(arg_func): | ||
# GH#47527 | ||
|
@@ -613,7 +643,7 @@ def test_map_defaultdict_ignore_na(): | |
mapping = defaultdict(int, {1: 10, np.nan: 42}) | ||
ser = Series([1, np.nan, 2]) | ||
result = ser.map(mapping) | ||
expected = Series([10, 0, 0]) | ||
expected = Series([10, 42, 0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this older testcase seemed incorrect & needed to be corrected with this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the discussion we had in #47585 the old behavior is correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh I see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @rhshadrach can you weigh in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on changing the behavior in this test. The 0 in question here is because
I think introducing a better lookup for NaN values makes sense, and brings this in line with the Series case:
|
||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.