Skip to content

DOC: fix DataFrame.isin docstring and doctests #22767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/doctests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ "$DOCTEST" ]; then

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

if [ $? -ne "0" ]; then
RET=1
Expand Down
17 changes: 9 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7430,8 +7430,7 @@ def to_period(self, freq=None, axis=0, copy=True):

def isin(self, values):
"""
Return boolean DataFrame showing whether each element in the
DataFrame is contained in values.
Whether each element in the DataFrame is contained in values.

Parameters
----------
Expand All @@ -7444,8 +7443,9 @@ def isin(self, values):

Returns
-------

DataFrame of booleans
DataFrame
DataFrame of boolean showing whether each element in the DataFrame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean -> booleans

is contained in values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a See Also section? I think DataFrame.eq and Series.str.isin are worth referencing.

Examples
--------
Expand All @@ -7458,23 +7458,24 @@ def isin(self, values):
1 False False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you start the example before the "when values is a list" with the constructor, and displaying the content of the original Dataframe (i.e. >>> df)

Also, I think the docstring would be clearer if we use a more real world example. For example, if the index is an animal name, and the columns are num_legs and num_wings, a df.isin([2]) having a True in falcon/wings is very easy to see what it's doing. And not so much in a foo, A, 1, 2, 3 kind of example.

2 True False

When ``values`` is a dict:
When ``values`` is a dict. Note that B doesn't match the 1 here.

>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [1, 4, 7]})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if we can use the same DataFrame for all the examples.

>>> df.isin({'A': [1, 3], 'B': [4, 7, 12]})
A B
0 True False # Note that B didn't match the 1 here.
0 True False
1 False True
2 True True

When ``values`` is a Series or DataFrame:
When ``values`` is a Series or DataFrame. Column A in `df2` has a
3, but not at index 1.

>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']})
>>> df2 = pd.DataFrame({'A': [1, 3, 3, 2], 'B': ['e', 'f', 'f', 'e']})
>>> df.isin(df2)
A B
0 True False
1 False False # Column A in `df2` has a 3, but not at index 1.
1 False False
2 True True
"""
if isinstance(values, dict):
Expand Down