| 3393 | |
| 3394 | |
| 3395 | def test_sort_indices_table(): |
| 3396 | table = pa.table({"a": [1, 1, None, 0], "b": [1, 0, 0, 1]}) |
| 3397 | |
| 3398 | result = pc.sort_indices(table, sort_keys=[("a", "ascending", "at_end")]) |
| 3399 | assert result.to_pylist() == [3, 0, 1, 2] |
| 3400 | result = pc.sort_indices( |
| 3401 | table, sort_keys=[(pc.field("a"), "ascending", "at_start")]) |
| 3402 | assert result.to_pylist() == [2, 3, 0, 1] |
| 3403 | |
| 3404 | result = pc.sort_indices( |
| 3405 | table, sort_keys=[("a", "descending", "at_end"), ("b", "ascending", "at_end")] |
| 3406 | ) |
| 3407 | assert result.to_pylist() == [1, 0, 3, 2] |
| 3408 | result = pc.sort_indices( |
| 3409 | table, sort_keys=[("a", "descending", "at_start"), ("b", "ascending", |
| 3410 | "at_start")]) |
| 3411 | assert result.to_pylist() == [2, 1, 0, 3] |
| 3412 | # Positional `sort_keys` |
| 3413 | result = pc.sort_indices( |
| 3414 | table, [("a", "descending", "at_start"), ("b", "ascending", "at_start")]) |
| 3415 | assert result.to_pylist() == [2, 1, 0, 3] |
| 3416 | |
| 3417 | with pytest.raises(ValueError, match="Must specify one or more sort keys"): |
| 3418 | pc.sort_indices(table) |
| 3419 | |
| 3420 | with pytest.raises(ValueError, |
| 3421 | match="Invalid sort key column: No match for.*unknown"): |
| 3422 | pc.sort_indices(table, sort_keys=[("unknown", "ascending", "at_end")]) |
| 3423 | |
| 3424 | with pytest.raises(ValueError, match="not a valid sort order"): |
| 3425 | pc.sort_indices(table, sort_keys=[("a", "nonscending", "at_end")]) |
| 3426 | |
| 3427 | |
| 3428 | def test_is_in(): |