raulcd commented on code in PR #13327:
URL: https://github.com/apache/arrow/pull/13327#discussion_r892212528
##########
python/pyarrow/tests/test_compute.py:
##########
@@ -2743,6 +2745,43 @@ def test_random():
pc.random(100, initializer=[])
[email protected](
+ "tiebreaker,expected_values",
+ [("min", [3, 1, 4, 6, 4, 6, 1]),
+ ("max", [3, 2, 5, 7, 5, 7, 2]),
+ ("first", [3, 1, 4, 6, 5, 7, 2]),
+ ("dense", [2, 1, 3, 4, 3, 4, 1])]
+)
+def test_rank_options_tiebreaker(tiebreaker, expected_values):
+ arr = pa.array([1.2, 0.0, 5.3, None, 5.3, None, 0.0])
+ rank_options = pc.RankOptions(sort_keys=[("b", "ascending")],
+ null_placement="at_end",
+ tiebreaker=tiebreaker)
+ result = pc.rank(arr, options=rank_options)
+ expected = pa.array(expected_values, type=pa.uint64())
+ assert result.equals(expected)
+
+
+def test_rank_options():
+ arr = pa.array([1.2, 0.0, 5.3, None, 5.3, None, 0.0])
+ expected = pa.array([3, 1, 4, 6, 5, 7, 2], type=pa.uint64())
+
+ # Ensure rank can be called without specifying options
+ result = pc.rank(arr)
+ assert result.equals(expected)
+
+ # Ensure default RankOptions
+ result = pc.rank(arr, options=pc.RankOptions())
+ assert result.equals(expected)
+
+ with pytest.raises(ValueError,
+ match=r'"NonExisting" is not a valid tiebreaker'):
+ rank_options = pc.RankOptions(sort_keys=[("b", "ascending")],
+ null_placement="at_end",
+ tiebreaker="NonExisting")
+ pc.rank(arr, options=rank_options)
Review Comment:
Thanks! I missed that :)
##########
python/pyarrow/tests/test_compute.py:
##########
@@ -2743,6 +2745,43 @@ def test_random():
pc.random(100, initializer=[])
[email protected](
+ "tiebreaker,expected_values",
+ [("min", [3, 1, 4, 6, 4, 6, 1]),
+ ("max", [3, 2, 5, 7, 5, 7, 2]),
+ ("first", [3, 1, 4, 6, 5, 7, 2]),
+ ("dense", [2, 1, 3, 4, 3, 4, 1])]
+)
+def test_rank_options_tiebreaker(tiebreaker, expected_values):
+ arr = pa.array([1.2, 0.0, 5.3, None, 5.3, None, 0.0])
+ rank_options = pc.RankOptions(sort_keys=[("b", "ascending")],
+ null_placement="at_end",
+ tiebreaker=tiebreaker)
+ result = pc.rank(arr, options=rank_options)
+ expected = pa.array(expected_values, type=pa.uint64())
+ assert result.equals(expected)
+
+
+def test_rank_options():
+ arr = pa.array([1.2, 0.0, 5.3, None, 5.3, None, 0.0])
+ expected = pa.array([3, 1, 4, 6, 5, 7, 2], type=pa.uint64())
+
+ # Ensure rank can be called without specifying options
+ result = pc.rank(arr)
+ assert result.equals(expected)
+
+ # Ensure default RankOptions
+ result = pc.rank(arr, options=pc.RankOptions())
+ assert result.equals(expected)
+
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]