Skip to content

ENH: Behaviour Series.isin with dataframe comparison is confusing [for discussion] #43460

@erfannariman

Description

@erfannariman

Right now we can compare a Series with a DataFrame through Series.isin, but is this expected / wanted behaviour?
I would say this should raise, since expectations can be pretty ambiguous here and is confusing to me.

Also the documentation right now states that the values parameter should be "set or list-like"

Code example:

values = list("ABCD")
s = pd.Series(values)
df = pd.DataFrame({"Column": values})

print(s)
0    A
1    B
2    C
3    D
dtype: object

print(df)
  Column
0      A
1      B
2      C
3      D
# comparing DataFrame to Series, this is okay (right?) and I understand the result
df.isin(s)

   Column
0    True
1    True
2    True
3    True


#  comparing a series to df, what do we expect here? Should this raise? Why do you want to compare a Series to a DataFrame?
s.isin(df)

0    False
1    False
2    False
3    False
dtype: bool

Proposal: when passing anything else than "set or list-like" should raise in Series.isin

Metadata

Metadata

Labels

Error ReportingIncorrect or improved errors from pandasNeeds DiscussionRequires discussion from core team before further actionisinisin method

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions