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