Skip to content

Commit 302d43a

Browse files
Moisanjorisvandenbossche
authored andcommitted
DOC: fix DataFrame.isin docstring and doctests (#22767)
1 parent 1c4130d commit 302d43a

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

ci/doctests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [ "$DOCTEST" ]; then
2121

2222
# DataFrame / Series docstrings
2323
pytest --doctest-modules -v pandas/core/frame.py \
24-
-k"-axes -combine -isin -itertuples -join -nlargest -nsmallest -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_dict -to_stata"
24+
-k"-axes -combine -itertuples -join -nlargest -nsmallest -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_dict -to_stata"
2525

2626
if [ $? -ne "0" ]; then
2727
RET=1

pandas/core/frame.py

+46-32
Original file line numberDiff line numberDiff line change
@@ -7451,52 +7451,66 @@ def to_period(self, freq=None, axis=0, copy=True):
74517451

74527452
def isin(self, values):
74537453
"""
7454-
Return boolean DataFrame showing whether each element in the
7455-
DataFrame is contained in values.
7454+
Whether each element in the DataFrame is contained in values.
74567455
74577456
Parameters
74587457
----------
7459-
values : iterable, Series, DataFrame or dictionary
7458+
values : iterable, Series, DataFrame or dict
74607459
The result will only be true at a location if all the
74617460
labels match. If `values` is a Series, that's the index. If
7462-
`values` is a dictionary, the keys must be the column names,
7461+
`values` is a dict, the keys must be the column names,
74637462
which must match. If `values` is a DataFrame,
74647463
then both the index and column labels must match.
74657464
74667465
Returns
74677466
-------
7467+
DataFrame
7468+
DataFrame of booleans showing whether each element in the DataFrame
7469+
is contained in values.
74687470
7469-
DataFrame of booleans
7471+
See Also
7472+
--------
7473+
DataFrame.eq: Equality test for DataFrame.
7474+
Series.isin: Equivalent method on Series.
7475+
Series.str.contains: Test if pattern or regex is contained within a
7476+
string of a Series or Index.
74707477
74717478
Examples
74727479
--------
7473-
When ``values`` is a list:
7474-
7475-
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']})
7476-
>>> df.isin([1, 3, 12, 'a'])
7477-
A B
7478-
0 True True
7479-
1 False False
7480-
2 True False
7481-
7482-
When ``values`` is a dict:
7483-
7484-
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [1, 4, 7]})
7485-
>>> df.isin({'A': [1, 3], 'B': [4, 7, 12]})
7486-
A B
7487-
0 True False # Note that B didn't match the 1 here.
7488-
1 False True
7489-
2 True True
7490-
7491-
When ``values`` is a Series or DataFrame:
7492-
7493-
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']})
7494-
>>> df2 = pd.DataFrame({'A': [1, 3, 3, 2], 'B': ['e', 'f', 'f', 'e']})
7495-
>>> df.isin(df2)
7496-
A B
7497-
0 True False
7498-
1 False False # Column A in `df2` has a 3, but not at index 1.
7499-
2 True True
7480+
7481+
>>> df = pd.DataFrame({'num_legs': [2, 4], 'num_wings': [2, 0]},
7482+
... index=['falcon', 'dog'])
7483+
>>> df
7484+
num_legs num_wings
7485+
falcon 2 2
7486+
dog 4 0
7487+
7488+
When ``values`` is a list check whether every value in the DataFrame
7489+
is present in the list (which animals have 0 or 2 legs or wings)
7490+
7491+
>>> df.isin([0, 2])
7492+
num_legs num_wings
7493+
falcon True True
7494+
dog False True
7495+
7496+
When ``values`` is a dict, we can pass values to check for each
7497+
column separately:
7498+
7499+
>>> df.isin({'num_wings': [0, 3]})
7500+
num_legs num_wings
7501+
falcon False False
7502+
dog False True
7503+
7504+
When ``values`` is a Series or DataFrame the index and column must
7505+
match. Note that 'falcon' does not match based on the number of legs
7506+
in df2.
7507+
7508+
>>> other = pd.DataFrame({'num_legs': [8, 2],'num_wings': [0, 2]},
7509+
... index=['spider', 'falcon'])
7510+
>>> df.isin(other)
7511+
num_legs num_wings
7512+
falcon True True
7513+
dog False False
75007514
"""
75017515
if isinstance(values, dict):
75027516
from pandas.core.reshape.concat import concat

0 commit comments

Comments
 (0)