-
Notifications
You must be signed in to change notification settings - Fork 4.2k
ARROW-16469: [Python] Table.filter accepts a boolean expression in addition to boolean array #13155
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2882,24 +2882,27 @@ cdef class Table(_PandasConvertible): | |
|
|
||
| return pyarrow_wrap_table(result) | ||
|
|
||
| def filter(self, mask, object null_selection_behavior="drop"): | ||
| def filter(self, mask_or_expr, object null_selection_behavior="drop"): | ||
| """ | ||
| Select rows from the table. | ||
|
|
||
| See :func:`pyarrow.compute.filter` for full usage. | ||
| The Table can be filtered based on a mask, which will be passed to | ||
| :func:`pyarrow.compute.filter` to perform the filtering, or it can | ||
| be filtered through a boolean :class:`.Expression` | ||
|
|
||
| Parameters | ||
| ---------- | ||
| mask : Array or array-like | ||
| The boolean mask to filter the table with. | ||
| mask_or_expr : Array or array-like or .Expression | ||
|
amol- marked this conversation as resolved.
Outdated
|
||
| The boolean mask or the :class:`.Expression` to filter the table with. | ||
| null_selection_behavior | ||
| How nulls in the mask should be handled. | ||
| How nulls in the mask should be handled, does nothing if | ||
| an :class:`.Expression` is used. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not possible to pass through to the filter node?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in any way that I can see, the filter node has a pretty straightforward constructor: I think that if you care about special handling nulls, you probably want to build an expression that evaluates as you wish for nulls
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think is possible to get the "emit null" behaviour by changing the expression (for dropping/keeping, you can explicitly fill the null with False/True, but for preserving the row as null, that's only possible through this option). I suppose that is a good reason this is an option of the filter kernel and not eg comparison kernels. Anyway, this is not that important given that the "drop" behaviour is the default for both (and is the typical behaviour you want, I think), but this might be something to open a JIRA for to add
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm, not sure I follow, why you can't use an expression? If I want to drop the nulls, I do If instead I want to keep the nulls, I do Regarding the "nulls" in the selection mask itself, I don't think FilterNode supports anything different from a boolean Expression, so the option doesn't make much sense in that context.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The option is about introducing nulls in the output data where the mask is null, not about preserving nulls from the input data. So for preserving nulls in the input, you can change your expression. But for introducing nulls, I don't think that is possible.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using your example table: vs The null is in a place where the original data had a "2" |
||
|
|
||
| Returns | ||
| ------- | ||
| filtered : Table | ||
| A table of the same schema, with only the rows selected | ||
| by the boolean mask. | ||
| by applied filtering | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -2932,7 +2935,11 @@ cdef class Table(_PandasConvertible): | |
| n_legs: [[2,4,null]] | ||
| animals: [["Flamingo","Horse",null]] | ||
| """ | ||
| return _pc().filter(self, mask, null_selection_behavior) | ||
| if isinstance(mask_or_expr, _pc().Expression): | ||
| return _pc()._exec_plan._filter_table(self, mask_or_expr, | ||
| output_type=Table) | ||
| else: | ||
| return _pc().filter(self, mask_or_expr, null_selection_behavior) | ||
|
|
||
| def take(self, object indices): | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.