pyarrow.compute.filter#

pyarrow.compute.filter(input, selection_filter, /, null_selection_behavior='drop', *, options=None, memory_pool=None)#

Filter with a boolean selection filter.

The output is populated with values from the input at positions where the selection filter is non-zero. Nulls in the selection filter are handled based on FilterOptions.

Parameters:
inputArray-like or scalar-like

Argument to compute function.

selection_filterArray-like or scalar-like

Argument to compute function.

null_selection_behaviorstr, default “drop”

How to handle nulls in the selection filter. Accepted values are “drop”, “emit_null”.

optionspyarrow.compute.FilterOptions, optional

Alternative way of passing options.

memory_poolpyarrow.MemoryPool, optional

If not passed, will allocate memory from the default memory pool.

Examples

>>> import pyarrow as pa
>>> arr = pa.array(["a", "b", "c", None, "e"])
>>> mask = pa.array([True, False, None, False, True])
>>> arr.filter(mask)
<pyarrow.lib.StringArray object at ...>
[
  "a",
  "e"
]
>>> arr.filter(mask, null_selection_behavior='emit_null')
<pyarrow.lib.StringArray object at ...>
[
  "a",
  null,
  "e"
]