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

Function test_rank_options

python/pyarrow/tests/test_compute.py:3993–4022  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3991
3992
3993def test_rank_options():
3994 arr = pa.array([1.2, 0.0, 5.3, None, 5.3, None, 0.0])
3995 expected = pa.array([3, 1, 4, 6, 5, 7, 2], type=pa.uint64())
3996
3997 # Ensure rank can be called without specifying options
3998 result = pc.rank(arr)
3999 assert result.equals(expected)
4000
4001 # Ensure default RankOptions
4002 result = pc.rank(arr, options=pc.RankOptions())
4003 assert result.equals(expected)
4004
4005 # Ensure sort_keys tuple usage
4006 result = pc.rank(arr, options=pc.RankOptions(
4007 sort_keys=[("b", "ascending", "at_end")])
4008 )
4009 assert result.equals(expected)
4010
4011 result = pc.rank(arr, sort_keys=[("", "ascending", "at_start")])
4012 expected_at_start = pa.array([5, 3, 6, 1, 7, 2, 4], type=pa.uint64())
4013 assert result.equals(expected_at_start)
4014
4015 result = pc.rank(arr, sort_keys="descending")
4016 expected_descending = pa.array([3, 4, 1, 6, 2, 7, 5], type=pa.uint64())
4017 assert result.equals(expected_descending)
4018
4019 with pytest.raises(ValueError,
4020 match=r'"NonExisting" is not a valid tiebreaker'):
4021 pc.RankOptions(sort_keys=[("", "descending", "at_end")],
4022 tiebreaker="NonExisting")
4023
4024
4025def test_rank_quantile_options():

Callers

nothing calls this directly

Calls 3

equalsMethod · 0.80
RankOptionsMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected