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

Function test_table_sort_by

python/pyarrow/tests/test_table.py:3519–3548  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

3517 ]
3518)
3519def test_table_sort_by(cls):
3520 table = cls.from_arrays([
3521 pa.array([3, 1, 4, 2, 5]),
3522 pa.array(["b", "a", "b", "a", "c"]),
3523 ], names=["values", "keys"])
3524
3525 assert table.sort_by("values").to_pydict() == {
3526 "keys": ["a", "a", "b", "b", "c"],
3527 "values": [1, 2, 3, 4, 5]
3528 }
3529
3530 assert table.sort_by([("values", "descending", "at_end")]).to_pydict() == {
3531 "keys": ["c", "b", "b", "a", "a"],
3532 "values": [5, 4, 3, 2, 1]
3533 }
3534
3535 tab = cls.from_arrays([
3536 pa.array([5, 7, 7, 35], type=pa.int64()),
3537 pa.array(["foo", "car", "bar", "foobar"])
3538 ], names=["a", "b"])
3539
3540 sorted_tab = tab.sort_by([("a", "descending", "at_end")])
3541 sorted_tab_dict = sorted_tab.to_pydict()
3542 assert sorted_tab_dict["a"] == [35, 7, 7, 5]
3543 assert sorted_tab_dict["b"] == ["foobar", "car", "bar", "foo"]
3544
3545 sorted_tab = tab.sort_by([("a", "ascending", "at_end")])
3546 sorted_tab_dict = sorted_tab.to_pydict()
3547 assert sorted_tab_dict["a"] == [5, 7, 7, 35]
3548 assert sorted_tab_dict["b"] == ["foo", "car", "bar", "foobar"]
3549
3550
3551def test_record_batch_sort():

Callers

nothing calls this directly

Calls 1

arrayMethod · 0.45

Tested by

no test coverage detected