Skip to content
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

feat: make DataFrame.__eq__ and DataFrame.__neq__ raise, point users towards nw.all #1484

Closed
MarcoGorelli opened this issue Dec 2, 2024 · 0 comments · Fixed by #1494
Closed

Comments

@MarcoGorelli
Copy link
Member

For Polars, df != 0 is equivalent to df.select(pl.all() != 0)

In Narwhals, however, we just return a single scalar False:

In [26]: df = pl.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7,8,9]})

In [27]: df != 0
Out[27]:
shape: (3, 3)
┌──────┬──────┬──────┐
│ abc    │
│ ---------  │
│ boolboolbool │
╞══════╪══════╪══════╡
│ truetruetrue │
│ truetruetrue │
│ truetruetrue │
└──────┴──────┴──────┘

In [28]: import narwhals as nw

In [29]: nw.from_native(df) != 0
Out[29]: True

We could match Polars' behaviour here:

  • for DataFrame, __eq__ should do select(nw.all()==0) and __neq__ should do select(nw.all()!=0)
  • for LazyFrame, both __eq__ and __neq__ should raise

but I think this is a chance to raise an informative error message and push people towards nw.all. In the long run, that's the solution that'll get them the furthest, as expressions are composable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant