pyarrow.compute.bottom_k_unstable#

pyarrow.compute.bottom_k_unstable(values, k, sort_keys=None, *, memory_pool=None)[source]#

Select the indices of the bottom-k ordered elements from array- or table-like data.

This is a specialization for select_k_unstable(). Output is not guaranteed to be stable.

Parameters:
valuesArray, ChunkedArray, RecordBatch, or Table

Data to sort and get bottom indices from.

kint

The number of k elements to keep.

sort_keysList-like

Column key names to order by when input is table-like data.

memory_poolMemoryPool, optional

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

Returns:
resultArray of indices

Indices of the bottom-k ordered elements

Examples

>>> import pyarrow as pa
>>> import pyarrow.compute as pc
>>> arr = pa.array(["a", "b", "c", None, "e", "f"])
>>> pc.bottom_k_unstable(arr, k=3)
<pyarrow.lib.UInt64Array object at ...>
[
  0,
  1,
  2
]