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