Skip to content

Adding test_map_missing_mixed to test_apply.py in pandas test suite series #20574

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 9 commits into from
Apr 3, 2018
Merged
10 changes: 10 additions & 0 deletions pandas/tests/series/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,13 @@ def f(x):
result = s.map(f)
exp = pd.Series(['Asia/Tokyo'] * 25, name='XX')
tm.assert_series_equal(result, exp)

@pytest.mark.parametrize("mapping,exp", [
({np.nan: 'not NaN'}, pd.Series(['not NaN'])),
({'string': 'another string' }, pd.Series(['another string'])),
({42: 'the answer'}, pd.Series(['the answer']))])
def test_map_missing_mixed(self, mapping, exp):
s = pd.Series(list(mapping.keys())[0])
Copy link
Member

Choose a reason for hiding this comment

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

Nice job on the parametrization but in the process of updating this line I think we are losing sight of what we are trying to test. Originally you were constructing this series from list('abcd') and appending an NA record. Now all you are doing is using the key of your dict as the series value, but that's not the same test.

Now that I'm thinking about it it's probably good to also add a "vals" parameter in front of the mapping. For the first two scenarios you can use list('abcd') as you had before and for the third use range(4). Then just make your first line s = pd.Series(vals + [np.nan])

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, I'll give that a shot.

result = s.map(mapping)

tm.assert_series_equal(result, exp)