@@ -13920,18 +13920,36 @@ def to_period(
13920
13920
setattr (new_obj , axis_name , new_ax )
13921
13921
return new_obj
13922
13922
13923
- def isin (self , values : Series | DataFrame | Sequence | Mapping ) -> DataFrame :
13923
+ def isin (
13924
+ self ,
13925
+ values : Series | DataFrame | Sequence | Mapping ,
13926
+ ignore_index : bool = False ,
13927
+ ) -> DataFrame :
13924
13928
"""
13925
13929
Whether each element in the DataFrame is contained in values.
13926
13930
13927
13931
Parameters
13928
13932
----------
13929
13933
values : iterable, Series, DataFrame or dict
13930
13934
The result will only be true at a location if all the
13931
- labels match. If `values` is a Series, that's the index. If
13932
- `values` is a dict, the keys must be the column names,
13933
- which must match. If `values` is a DataFrame,
13934
- then both the index and column labels must match.
13935
+ labels match.
13936
+ - If `values` is a Series, the index labels must match.
13937
+ - If `values` is a dict, the keys must be column names,
13938
+ which must match.
13939
+ - If `values` is a DataFrame:
13940
+ * When ``ignore_index=False`` (default), both the index
13941
+ and column labels must match, and comparison is done
13942
+ elementwise.
13943
+ * When ``ignore_index=True``, only column labels must
13944
+ match. Each element in the DataFrame is compared
13945
+ against the set of values in the corresponding column
13946
+ of ``values``, ignoring row index alignment.
13947
+
13948
+ ignore_index : bool, default False
13949
+ *Only valid when `values` is a DataFrame.*
13950
+ If True, ignore index alignment and simply check
13951
+ if each value in each column occurs in the same
13952
+ column of `values`.
13935
13953
13936
13954
Returns
13937
13955
-------
@@ -14012,9 +14030,12 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame:
14012
14030
raise ValueError ("cannot compute isin with a duplicate axis." )
14013
14031
result = self .eq (values .reindex_like (self ), axis = "index" )
14014
14032
elif isinstance (values , DataFrame ):
14015
- if not (values .columns .is_unique and values .index .is_unique ):
14016
- raise ValueError ("cannot compute isin with a duplicate axis." )
14017
- result = self .eq (values .reindex_like (self ))
14033
+ if ignore_index :
14034
+ result = self .isin (values .to_dict ("list" ))
14035
+ else :
14036
+ if not (values .columns .is_unique and values .index .is_unique ):
14037
+ raise ValueError ("cannot compute isin with a duplicate axis." )
14038
+ result = self .eq (values .reindex_like (self ))
14018
14039
else :
14019
14040
if not is_list_like (values ):
14020
14041
raise TypeError (
0 commit comments