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: Bitwise operations / aggregations #18994

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

coastalwhite
Copy link
Collaborator

@coastalwhite coastalwhite commented Sep 28, 2024

This implements the bitwise namespace for expressions that allows performing bitwise operations on booleans, integers and floating point values. This also allows for bitwise aggregations.

List of implemented functions:

  • bitwise_count_ones
  • bitwise_count_zeros
  • bitwise_leading_ones
  • bitwise_leading_zeros
  • bitwise_trailing_ones
  • bitwise_trailing_zeros
  • bitwise_and
  • bitwise_or
  • bitwise_xor

This implements the `bitwise` namespace for expressions that allows performing
bitwise operations on booleans, integers and floating point values. This also
allows for bitwise aggregations.

List of implemented functions:

- [x] `bitwise.count_ones`
- [x] `bitwise.count_zeros`
- [x] `bitwise.leading_ones`
- [x] `bitwise.leading_zeros`
- [x] `bitwise.trailing_ones`
- [x] `bitwise.trailing_zeros`
- [ ] `bitwise.and`
- [ ] `bitwise.or`
- [ ] `bitwise.xor`

[skip ci]
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Sep 28, 2024
@@ -10472,6 +10472,60 @@ def replace_strict(
self._pyexpr.replace_strict(old, new, default, return_dtype)
)

def bitwise_count_ones(self) -> Expr:
Copy link
Member

@ritchie46 ritchie46 Sep 30, 2024

Choose a reason for hiding this comment

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

We can add these to Series as well. If you create the functions without implementing them, they will automagically dispatch to these expresssions (via a decorator).

And then the docs entries. :)

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 rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants