MCPcopy Create free account
hub / github.com/apache/arrow / bottom_k_unstable

Function bottom_k_unstable

python/pyarrow/compute.py:623–673  ·  view source on GitHub ↗

Select the indices of the bottom-k ordered elements from array- or table-like data. This is a specialization for :func:`select_k_unstable`. Output is not guaranteed to be stable. Parameters ---------- values : Array, ChunkedArray, RecordBatch, or Table Data to

(
        values, k, sort_keys=None, null_placements=None, *, memory_pool=None)

Source from the content-addressed store, hash-verified

621
622
623def bottom_k_unstable(
624 values, k, sort_keys=None, null_placements=None, *, memory_pool=None):
625 """
626 Select the indices of the bottom-k ordered elements from
627 array- or table-like data.
628
629 This is a specialization for :func:`select_k_unstable`. Output is not
630 guaranteed to be stable.
631
632 Parameters
633 ----------
634 values : Array, ChunkedArray, RecordBatch, or Table
635 Data to sort and get bottom indices from.
636 k : int
637 The number of `k` elements to keep.
638 sort_keys : List-like
639 Column key names to order by when input is table-like data.
640 null_placements : A list of "at_start" or "at_end"
641 Whether nulls and NaNs are placed at the start or at the end.
642 Accepted values are "at_end", "at_start".
643 memory_pool : MemoryPool, optional
644 If not passed, will allocate memory from the default memory pool.
645
646 Returns
647 -------
648 result : Array of indices
649 Indices of the bottom-k ordered elements
650
651 Examples
652 --------
653 >>> import pyarrow as pa
654 >>> import pyarrow.compute as pc
655 >>> arr = pa.array(["a", "b", "c", None, "e", "f"])
656 >>> pc.bottom_k_unstable(arr, k=3)
657 <pyarrow.lib.UInt64Array object at ...>
658 [
659 0,
660 1,
661 2
662 ]
663 """
664 if sort_keys is None:
665 sort_keys = []
666 if isinstance(values, (pa.Array, pa.ChunkedArray)):
667 sort_keys.append(("dummy", "ascending", "at_end"))
668 else:
669 sort_keys = [(sort_key, "ascending", null_placement)
670 for sort_key, null_placement in zip(sort_keys, null_placements)]
671
672 options = SelectKOptions(k, sort_keys)
673 return call_function("select_k_unstable", [values], options, memory_pool)
674
675
676def random(n, *, initializer='system', options=None, memory_pool=None):

Callers

nothing calls this directly

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected