Skip to content

GH-39220: [Python] Let RecordBatch.filter accept a boolean expression in addition to mask array #43043

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

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Jun 25, 2024

Rationale for this change

Table.filter() already accepted either a boolean mask array or a boolean expression. But the equivalent method on RecordBatch only accepted the array. This makes both methods consistent in accepting both types of mask.

What changes are included in this PR?

Consolidate the Table.filter and RecordBatch.fitler methods into a single shared method on the base class, and expanded the _filter_table Acero helper to also work with RecordBatch in addition to Table (and ensure to return a batch if the input was a batch)

Are these changes tested?

Yes

Copy link

⚠️ GitHub issue #39220 has been automatically assigned in GitHub to PR creator.

Copy link
Member

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

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

Does this mean Table.filter() will no longer work if PyArrow was not built with Acero? I forget how optional that is considered.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Jun 25, 2024
@jorisvandenbossche
Copy link
Member Author

Does this mean Table.filter() will no longer work if PyArrow was not built with Acero? I forget how optional that is considered.

It will still work without Acero for a plain boolean mask (in that case we only require the compute kernel), only for filtering with an expression it needs Acero.

(and note this was already the case for Table.filter, this PR is just adding the same capability to RecordBatch.filter)

Copy link
Member

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

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

That makes sense. Thanks for explaining!

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting changes Awaiting changes labels Jun 26, 2024
@wjones127 wjones127 merged commit 577cafb into apache:main Jun 26, 2024
12 of 14 checks passed
@wjones127 wjones127 removed the awaiting merge Awaiting merge label Jun 26, 2024
@jorisvandenbossche jorisvandenbossche deleted the gh-39220-recordbatch-filter branch June 26, 2024 15:32
Copy link

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit 577cafb.

There was 1 benchmark result indicating a performance regression:

The full Conbench report has more details. It also includes information about 12 possible false positives for unstable benchmarks that are known to sometimes produce them.

zanmato1984 pushed a commit to zanmato1984/arrow that referenced this pull request Jul 9, 2024
…ession in addition to mask array (apache#43043)

### Rationale for this change

`Table.filter()` already accepted either a boolean mask array or a boolean expression. But the equivalent method on `RecordBatch` only accepted the array. This makes both methods consistent in accepting both types of mask.

### What changes are included in this PR?

Consolidate the `Table.filter` and `RecordBatch.fitler` methods into a single shared method on the base class, and expanded the `_filter_table` Acero helper to also work with RecordBatch in addition to Table (and ensure to return a batch if the input was a batch)

### Are these changes tested?
Yes
* GitHub Issue: apache#39220

Authored-by: Joris Van den Bossche <[email protected]>
Signed-off-by: Will Jones <[email protected]>
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.

2 participants