jorisvandenbossche commented on code in PR #13327:
URL: https://github.com/apache/arrow/pull/13327#discussion_r891424056
##########
python/pyarrow/_compute.pyx:
##########
@@ -2047,6 +2047,60 @@ class RandomOptions(_RandomOptions):
self._set_options(length, initializer)
+cdef class _RankOptions(FunctionOptions):
+
+ _tiebreaker_map = {
+ "Min": CRankOptionsTiebreaker_MIN,
+ "Max": CRankOptionsTiebreaker_MAX,
+ "First": CRankOptionsTiebreaker_FIRST,
+ "Dense": CRankOptionsTiebreaker_DENSE,
+ }
+
+ def _set_options(self, sort_keys, null_placement, tiebreaker):
+ cdef vector[CSortKey] c_sort_keys
+ for name, order in sort_keys:
+ c_sort_keys.push_back(
+ CSortKey(tobytes(name), unwrap_sort_order(order))
+ )
+ try:
+ self.wrapped.reset(
+ new CRankOptions(c_sort_keys,
unwrap_null_placement(null_placement), self._tiebreaker_map[tiebreaker])
+ )
+ except KeyError:
+ _raise_invalid_function_option(tiebreaker, "tiebreaker")
+
+
+class RankOptions(_RankOptions):
+ """
+ Options for the `rank` function.
+
+ Parameters
+ ----------
+ sort_keys : sequence of (name, order) tuples
Review Comment:
Although for `sort_indices` we have a separate array-specific kernel with a
separate ArraySortOptions (which is simpler, not requiring a column name), in
addition to the general SortOptions. So that's a bit different here.
For the `sort_keys` keyword in top_k / bottom_k kernel, we have some special
casing as well:
https://github.com/apache/arrow/blob/62979d249952775ebd06c814b16d58b87e1cbc88/python/pyarrow/compute.py#L544-L547
(the "descending" is hardcoded here because it is for `top_k`, but the
relevant part is that is injects a "dummy" name for the column in case of array
input)
--
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]