Skip to content

Commit e089122

Browse files
jaredsnyderTomAugspurger
authored andcommitted
BUG: fix isin with Series of tuples values (#16394) (#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 (cherry picked from commit e053ee3)
1 parent 0ffce83 commit e089122

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

doc/source/whatsnew/v0.20.2.txt

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ Reshaping
8686
- Bug in ``Series.isin(..)`` with a list of tuples (:issue:`16394`)
8787
- Bug in construction of a ``DataFrame`` with mixed dtypes including an all-NaT column. (:issue:`16395`)
8888

89-
90-
9189
Numeric
9290
^^^^^^^
9391
- Bug in .interpolate(), where limit_direction was not respected when limit=None (default) was passed (:issue:16282)

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def isin(comps, values):
388388
"[{0}]".format(type(values).__name__))
389389

390390
if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
391-
values = np.array(list(values), dtype='object')
391+
values = lib.list_to_object_array(list(values))
392392

393393
comps, dtype, _ = _ensure_data(comps)
394394
values, _, _ = _ensure_data(values, dtype=dtype)

pandas/tests/frame/test_analytics.py

+8
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,14 @@ def test_isin_df(self):
12011201
expected['B'] = False
12021202
tm.assert_frame_equal(result, expected)
12031203

1204+
def test_isin_tuples(self):
1205+
# GH16394
1206+
df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']})
1207+
df['C'] = list(zip(df['A'], df['B']))
1208+
result = df['C'].isin([(1, 'a')])
1209+
tm.assert_series_equal(result,
1210+
Series([True, False, False], name="C"))
1211+
12041212
def test_isin_df_dupe_values(self):
12051213
df1 = DataFrame({'A': [1, 2, 3, 4], 'B': [2, np.nan, 4, 4]})
12061214
# just cols duped

0 commit comments

Comments
 (0)