Skip to content

Commit 3b39a10

Browse files
authored
REGR: MultiIndex.isin raising TypeError for generator (#52572)
* REGR: MultiIndex.isin raising TypeError for generator * Update v2.0.1.rst
1 parent 8111099 commit 3b39a10

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v2.0.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed regressions
1616
- Fixed regression for subclassed Series when constructing from a dictionary (:issue:`52445`)
1717
- Fixed regression in :meth:`Series.describe` showing ``RuntimeWarning`` for extension dtype :class:`Series` with one element (:issue:`52515`)
1818
- Fixed regression in :meth:`DataFrame.sort_values` not resetting index when :class:`DataFrame` is already sorted and ``ignore_index=True`` (:issue:`52553`)
19+
- Fixed regression in :meth:`MultiIndex.isin` raising ``TypeError`` for ``Generator`` (:issue:`52568`)
1920

2021
.. ---------------------------------------------------------------------------
2122
.. _whatsnew_201.bug_fixes:

pandas/core/indexes/multi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Any,
88
Callable,
99
Collection,
10+
Generator,
1011
Hashable,
1112
Iterable,
1213
List,
@@ -3772,6 +3773,9 @@ def delete(self, loc) -> MultiIndex:
37723773

37733774
@doc(Index.isin)
37743775
def isin(self, values, level=None) -> npt.NDArray[np.bool_]:
3776+
if isinstance(values, Generator):
3777+
values = list(values)
3778+
37753779
if level is None:
37763780
if len(values) == 0:
37773781
return np.zeros((len(self),), dtype=np.bool_)

pandas/tests/indexes/multi/test_isin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@ def test_isin_empty():
9393
result = midx.isin([])
9494
expected = np.array([False, False])
9595
tm.assert_numpy_array_equal(result, expected)
96+
97+
98+
def test_isin_generator():
99+
# GH#52568
100+
midx = MultiIndex.from_tuples([(1, 2)])
101+
result = midx.isin(x for x in [(1, 2)])
102+
expected = np.array([True])
103+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)