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(python): boolean Series broadcast comparison (eq/neq) against scalar True/False #6797

Merged

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Feb 11, 2023

Closes #6587.

Something of an edge-case, as technically the Series is already its own result (or inverse result) here. Implemented as a special-case inside _comp, returning self.clone() or ~self based on the given comparison op (eq/neq) and value.

Example

Before (doesn't broadcast the comparison)

s = pl.Series("bools", [True, True, True, False])

print( s == True )
# False

print( s == False )
# False

After (consistent with all the other Series/scalar broadcast comparisons)

s = pl.Series("bools", [True, True, True, False])

print( s == True )

# shape: (4,)
# Series: 'bools' [bool]
# [
# 	true
# 	true
# 	true
# 	false
# ]

print( s == False )

# shape: (4,)
# Series: 'bools' [bool]
# [
# 	false
# 	false
# 	false
# 	true
# ]

Note: comparing boolean series with gt,ge,lt,le remains an error.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Feb 11, 2023
@ritchie46
Copy link
Member

Yeap, good one. Thanks!

@ritchie46 ritchie46 merged commit b5fa39c into pola-rs:master Feb 11, 2023
@alexander-beedie
Copy link
Collaborator Author

Yeap, good one. Thanks!

Feeling motivated to push that issue counter back under 400, lol...

@alexander-beedie alexander-beedie deleted the boolean-series-comparison branch February 11, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

comparison operators on boolean series are NotImplemented
2 participants