polars.Series.gather#

Series.gather(
indices: int | list_[int] | Expr | Series | np.ndarray[Any, Any],
*,
null_on_oob: bool = False,
) Series[source]#

Take values by index.

Parameters:
indices

Index location used for selection.

null_on_oob

Behavior if an index is out of bounds:

  • True -> set the result to null

  • False -> raise an error

Examples

>>> s = pl.Series("a", [1, 2, 3, 4])
>>> s.gather([1, 3])
shape: (2,)
Series: 'a' [i64]
[
    2
    4
]

Use null_on_oob=True to return null for out-of-bounds indices.

>>> s.gather([1, 10], null_on_oob=True)
shape: (2,)
Series: 'a' [i64]
[
    2
    null
]