Skip to content

Add logical operator support (__and__/__or__ methods on dataframe and column) #171

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
Jun 20, 2023

Conversation

MarcoGorelli
Copy link
Contributor

@MarcoGorelli MarcoGorelli commented May 18, 2023

Also a typo fix for __add__.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This really was meant to be __add__ I suspect, not __and__, since it came in with the update to Column which matched DataFrame methods, and lives right above __sub__ - and __add__ was part of the arithmetic methods in gh-94. Also, the docstring says "dataframe" and that should be "column".

Adding __and__ and __or__ too seems very reasonable though, I think we can have both __add__ and __and__ here.

@MarcoGorelli MarcoGorelli marked this pull request as draft May 18, 2023 15:10
@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 18, 2023 16:56
@MarcoGorelli
Copy link
Contributor Author

good catch, thanks, have updated

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Marco. The other thing that I thought for a minute should perhaps be different is the error type, however ValueError is also used by any/all when the dtype isn't bool. So this should be uncontroversial I think.

@rgommers rgommers changed the title Fix __and__ docsting, add __or__ And logical operator support (__and__/__or__ methods on dataframe and column) May 20, 2023
@rgommers
Copy link
Member

I plan to merge this within the next couple of days, unless there is a concern about adding __and__ and __or__.

@kkraus14
Copy link
Collaborator

Should we clarify whether Kleene logic is used for these or not (to clarify null behavior)?

Also, it looks like for __and__ we're requiring bools, but for __or__ it's more generically Scalar. Should these be consistent?

@MarcoGorelli
Copy link
Contributor Author

MarcoGorelli commented May 22, 2023

but for or it's more generically Scalar.

I think it's also bools there?

def __or__(self, other: Column[bool] | bool) -> Column:

it's __add__ which can more generically take a Scalar

EDIT: nvm, the docstring did in fact say 'Scalar' - have updated, thanks!

@rgommers
Copy link
Member

Should we clarify whether Kleene logic is used for these or not (to clarify null behavior)?

That would be good to add indeed. With the answer being that yes, Kleene logic is used I'd think - I assume that's true for all libraries?

Related: we probably should add __bool__ and make it raise, because truthiness of a column/dataframe is not defined.

@jorisvandenbossche
Copy link
Member

I assume that's true for all libraries?

Not for the default (numpy based) data types in pandas. But I would say that's a problem to tackle for pandas / the package implementing this standard on top of pandas. I agree we should specify that it is expected use Kleene logic.

BTW, we should also specify the behaviour of nulls in the comparison methods (__eq__, __lt__, and friends)

@MarcoGorelli MarcoGorelli changed the title And logical operator support (__and__/__or__ methods on dataframe and column) Add logical operator support (__and__/__or__ methods on dataframe and column) Jun 15, 2023
@MarcoGorelli
Copy link
Contributor Author

I've noted that nulls should follow kleene logic - any further requests?

@MarcoGorelli
Copy link
Contributor Author

merging then - thanks for your reviews!

@MarcoGorelli MarcoGorelli merged commit 30b242d into data-apis:main Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants