From e3ae4a18395c8290ce74a4c55aee69c0b480ac7a Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Fri, 30 Mar 2018 09:08:10 -0400 Subject: [PATCH 1/9] Adding test_map_missing_mixed to test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 0780c846a6c19..0db640f5fd74c 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -576,3 +576,11 @@ def f(x): result = s.map(f) exp = pd.Series(['Asia/Tokyo'] * 25, name='XX') tm.assert_series_equal(result, exp) + + def test_map_missing_mixed(self): + s = pd.Series(list('abc') + [np.nan]) + + result = s.map({np.nan: 'not NaN'}) + result2 = s.map({'a': 42, np.nan: 'not NaN'}) + + tm.assert_series_equal(result, result2) From 02e48d5c3e008061612d7e8315683097dc309b15 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Fri, 30 Mar 2018 09:42:54 -0400 Subject: [PATCH 2/9] Fixing test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 0db640f5fd74c..eb7b7ff59e262 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -583,4 +583,4 @@ def test_map_missing_mixed(self): result = s.map({np.nan: 'not NaN'}) result2 = s.map({'a': 42, np.nan: 'not NaN'}) - tm.assert_series_equal(result, result2) + tm.assert_series_equal(result[-1:], result2[-1:]) From c7402a6a0258d39f06353861c3b987a3d7f38092 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 00:14:46 -0400 Subject: [PATCH 3/9] Eliminating extra whitespace in test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index eb7b7ff59e262..6829b17f5dd47 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -579,7 +579,7 @@ def f(x): def test_map_missing_mixed(self): s = pd.Series(list('abc') + [np.nan]) - + result = s.map({np.nan: 'not NaN'}) result2 = s.map({'a': 42, np.nan: 'not NaN'}) From 6ba3f07db871fcae40e4559787883d49b3196550 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 00:56:12 -0400 Subject: [PATCH 4/9] Parametrizing test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 6829b17f5dd47..3ebbd3c5610b5 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -577,10 +577,12 @@ def f(x): exp = pd.Series(['Asia/Tokyo'] * 25, name='XX') tm.assert_series_equal(result, exp) - def test_map_missing_mixed(self): - s = pd.Series(list('abc') + [np.nan]) + @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]) + result = s.map(mapping) - result = s.map({np.nan: 'not NaN'}) - result2 = s.map({'a': 42, np.nan: 'not NaN'}) - - tm.assert_series_equal(result[-1:], result2[-1:]) + tm.assert_series_equal(result, exp) From 50f12d7d631c031d604b31b8489a56902d48d893 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 00:58:03 -0400 Subject: [PATCH 5/9] Eliminating extra whitespace in test_map_missing_mixed in test_apply.py in pandas test suite series (again) --- pandas/tests/series/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 3ebbd3c5610b5..0874a68f6a5db 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -579,7 +579,7 @@ def f(x): @pytest.mark.parametrize("mapping,exp", [ ({np.nan: 'not NaN'}, pd.Series(['not NaN'])), - ({'string': 'another string' }, pd.Series(['another string'])), + ({'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]) From 138d0969b63be74d597d2b8920451d58983d570f Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 01:17:03 -0400 Subject: [PATCH 6/9] Refining parametrization in test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 0874a68f6a5db..e4607062772c6 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -577,12 +577,12 @@ def f(x): 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]) + @pytest.mark.parametrize("vals,mapping,exp", [ + (list('abc'), {np.nan: 'not NaN'}, pd.Series(['not NaN'])), + (list('abc'), {'string': 'another string'}, pd.Series(['another string'])), + (list(range(3)), {42: 'the answer'}, pd.Series(['the answer']))]) + def test_map_missing_mixed(self, vals, mapping, exp): + s = pd.Series(vals + [list(mapping.keys())[0]]) result = s.map(mapping) - tm.assert_series_equal(result, exp) + tm.assert_series_equal(result[-1:].reset_index(drop=True), exp) From 9a88dd2e7a490dfc47981f42b8290cf829446003 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 01:22:26 -0400 Subject: [PATCH 7/9] Refactoring test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index e4607062772c6..93678ea4ad90a 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -578,11 +578,11 @@ def f(x): tm.assert_series_equal(result, exp) @pytest.mark.parametrize("vals,mapping,exp", [ - (list('abc'), {np.nan: 'not NaN'}, pd.Series(['not NaN'])), - (list('abc'), {'string': 'another string'}, pd.Series(['another string'])), - (list(range(3)), {42: 'the answer'}, pd.Series(['the answer']))]) + (list('abc'), {np.nan: 'not NaN'}, ['not NaN']), + (list('abc'), {'string': 'another string'}, ['another string']), + (list(range(3)), {42: 'the answer'}, ['the answer'])]) def test_map_missing_mixed(self, vals, mapping, exp): s = pd.Series(vals + [list(mapping.keys())[0]]) result = s.map(mapping) - tm.assert_series_equal(result[-1:].reset_index(drop=True), exp) + tm.assert_series_equal(result[-1:].reset_index(drop=True), pd.Series(exp)) From 60ef5035a0364838a65523e61b7b6dbd073bec03 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 01:46:39 -0400 Subject: [PATCH 8/9] Fixing logical errors in test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 93678ea4ad90a..69d8528ea1c74 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -578,11 +578,11 @@ def f(x): tm.assert_series_equal(result, exp) @pytest.mark.parametrize("vals,mapping,exp", [ - (list('abc'), {np.nan: 'not NaN'}, ['not NaN']), - (list('abc'), {'string': 'another string'}, ['another string']), - (list(range(3)), {42: 'the answer'}, ['the answer'])]) + (list('abc'), {np.nan: 'not NaN'}, [np.nan] * 3 + ['not NaN']), + (list('abc'), {'a': 'a letter'}, ['a letter'] + [np.nan] * 3), + (list(range(3)), {0: 42}, [42] + [np.nan] * 3)]) def test_map_missing_mixed(self, vals, mapping, exp): - s = pd.Series(vals + [list(mapping.keys())[0]]) + s = pd.Series(vals + [np.nan]) result = s.map(mapping) - tm.assert_series_equal(result[-1:].reset_index(drop=True), pd.Series(exp)) + tm.assert_series_equal(result, pd.Series(exp)) From e927be4fc32cde1b727da6e586a5f3617c306664 Mon Sep 17 00:00:00 2001 From: Lynn Bradshaw Date: Mon, 2 Apr 2018 20:03:37 -0400 Subject: [PATCH 9/9] Adding issue tag to test_map_missing_mixed in test_apply.py in pandas test suite series --- pandas/tests/series/test_apply.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 69d8528ea1c74..b28b9f342695f 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -582,6 +582,7 @@ def f(x): (list('abc'), {'a': 'a letter'}, ['a letter'] + [np.nan] * 3), (list(range(3)), {0: 42}, [42] + [np.nan] * 3)]) def test_map_missing_mixed(self, vals, mapping, exp): + # GH20495 s = pd.Series(vals + [np.nan]) result = s.map(mapping)