pyarrow.compute.filter

pyarrow.compute.filter(data, mask, null_selection_behavior='drop')[source]

Select values (or records) from array- or table-like data given boolean filter, where true values are selected.

Parameters
  • data (Array, ChunkedArray, RecordBatch, or Table) –

  • mask (Array, ChunkedArray) – Must be of boolean type

  • null_selection_behavior (str, default 'drop') –

    Configure the behavior on encountering a null slot in the mask. Allowed values are ‘drop’ and ‘emit_null’.

    • ’drop’: nulls will be treated as equivalent to False.

    • ’emit_null’: nulls will result in a null in the output.

Returns

result (depends on inputs)

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 0x7fa826df9200>
[
  "a",
  "e"
]
>>> arr.filter(mask, null_selection_behavior='emit_null')
<pyarrow.lib.StringArray object at 0x7fa826df9200>
[
  "a",
  null,
  "e"
]