Skip to content

Commit

Permalink
BUG: fix isin with Series of tuples values (pandas-dev#16394) (pandas…
Browse files Browse the repository at this point in the history
…-dev#16434)

* 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
  • Loading branch information
jaredsnyder authored and stangirala committed Jun 11, 2017
1 parent 5ff2d2e commit 474f793
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Reshaping
^^^^^^^^^

- Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`)

- Bug in ``Series.isin(..)`` with a list of tuples (:issue:`16394`)

Numeric
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,14 @@ def test_isin_df(self):
expected['B'] = False
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"))

def test_isin_df_dupe_values(self):
df1 = DataFrame({'A': [1, 2, 3, 4], 'B': [2, np.nan, 4, 4]})
# just cols duped
Expand Down

0 comments on commit 474f793

Please sign in to comment.