From db346e3bbcef1a1b3661b9a0a7c537ac256f7dfd Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Mon, 22 May 2017 14:26:54 -0500 Subject: [PATCH 1/6] Swiched out "values = np.array(list(values), dtype='object')" for "values = lib.list_to_object_array(list(values))" in the isin() method found in core/algorithms.py Added test for comparing to a list of tuples --- pandas/core/algorithms.py | 2 +- pandas/tests/frame/test_analytics.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index a745ec616eda8..77d79c9585e57 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -388,7 +388,7 @@ def isin(comps, values): "[{0}]".format(type(values).__name__)) if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)): - values = np.array(list(values), dtype='object') + values = lib.list_to_object_array(list(values)) comps, dtype, _ = _ensure_data(comps) values, _, _ = _ensure_data(values, dtype=dtype) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index fa9823bf000a2..d9e99601e619a 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1201,6 +1201,13 @@ def test_isin_df(self): expected['B'] = False tm.assert_frame_equal(result, expected) + def test_isin_tuples(self): + df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']}) + df['C'] = list(zip(df['A'], df['B'])) + result = df['C'].isin([(1, 'a')]) + tm.assert_series_equal(result, + Series([True,False,False],name="C")) + def test_isin_df_dupe_values(self): df1 = DataFrame({'A': [1, 2, 3, 4], 'B': [2, np.nan, 4, 4]}) # just cols duped From 4d192a09278303f44ba01092b21338adcf059e03 Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Mon, 22 May 2017 15:32:42 -0500 Subject: [PATCH 2/6] - Added comment w/ issue number to test - Fixed PEP8 formatting issue in test --- pandas/tests/frame/test_analytics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index d9e99601e619a..1dfa6a910a5d1 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1202,11 +1202,12 @@ def test_isin_df(self): tm.assert_frame_equal(result, expected) def test_isin_tuples(self): + # GH16394 df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']}) df['C'] = list(zip(df['A'], df['B'])) result = df['C'].isin([(1, 'a')]) tm.assert_series_equal(result, - Series([True,False,False],name="C")) + Series([True,False,False],name="C")) def test_isin_df_dupe_values(self): df1 = DataFrame({'A': [1, 2, 3, 4], 'B': [2, np.nan, 4, 4]}) From 1a98fdc468c7a8866f3fd6bdcc3d61f85d4a8fdd Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Mon, 22 May 2017 15:38:09 -0500 Subject: [PATCH 3/6] Added line to whatsnew file --- doc/source/whatsnew/v0.20.2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index e0857019d2fd4..3a6c3a3675e4b 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -80,7 +80,7 @@ Reshaping ^^^^^^^^^ - Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`) - +- Bug in ``isin`` in core/algorithms.py with comparing lists of tuples Numeric ^^^^^^^ From 4dc6bc5aa9587fa3f32f1f2add570666686b6fe6 Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Mon, 22 May 2017 17:36:55 -0500 Subject: [PATCH 4/6] Fixed formatting issue in whatsnew doc --- doc/source/whatsnew/v0.20.2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 3a6c3a3675e4b..c3a820b9f47a2 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -80,7 +80,7 @@ Reshaping ^^^^^^^^^ - Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`) -- Bug in ``isin`` in core/algorithms.py with comparing lists of tuples +- Bug in ``Series.isin(..)`` in core/algorithms.py with a list of tuples (:issue:`16394`) Numeric ^^^^^^^ From e71219d6014928e64d59f7c8412f5c5a3de48856 Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Mon, 22 May 2017 17:49:00 -0500 Subject: [PATCH 5/6] Fixed PEP8 issues in test --- pandas/tests/frame/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 1dfa6a910a5d1..da96fce36f3c9 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1207,7 +1207,7 @@ def test_isin_tuples(self): df['C'] = list(zip(df['A'], df['B'])) result = df['C'].isin([(1, 'a')]) tm.assert_series_equal(result, - Series([True,False,False],name="C")) + Series([True, False, False], name="C")) def test_isin_df_dupe_values(self): df1 = DataFrame({'A': [1, 2, 3, 4], 'B': [2, np.nan, 4, 4]}) From ce622e63df0d4c69ac5644d27a95a2b732cbf755 Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Mon, 22 May 2017 19:58:06 -0500 Subject: [PATCH 6/6] Fixed text in whatsnew --- doc/source/whatsnew/v0.20.2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index c3a820b9f47a2..57625b725ddba 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -80,7 +80,7 @@ Reshaping ^^^^^^^^^ - Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`) -- Bug in ``Series.isin(..)`` in core/algorithms.py with a list of tuples (:issue:`16394`) +- Bug in ``Series.isin(..)`` with a list of tuples (:issue:`16394`) Numeric ^^^^^^^