You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/26 10:07:47 UTC

[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #14369: ARROW-14656: [Python] Add sort helper function for Array, ChunkedArray and StructArray

jorisvandenbossche commented on code in PR #14369:
URL: https://github.com/apache/arrow/pull/14369#discussion_r1005472486


##########
python/pyarrow/array.pxi:
##########
@@ -1402,6 +1402,22 @@ cdef class Array(_PandasConvertible):
         """
         return _pc().index(self, value, start, end, memory_pool=memory_pool)
 
+    def sort(self, order="ascending"):

Review Comment:
   The `sort_indices` kernel also has a `null_placement` keyword, that could maybe be exposed here as well? (or pass through kwargs)



##########
python/pyarrow/array.pxi:
##########
@@ -2746,6 +2762,29 @@ cdef class StructArray(Array):
         result.validate()
         return result
 
+    def sort(self, order="ascending", fieldname=None):
+        """
+        Sort the StructArray
+
+        Parameters
+        ----------
+        order : "ascending" or "descending"
+            The order of the sorting.

Review Comment:
   Maybe can use the same entry as for array_sort_indices to keep things consistent:
   
   ```
   order : str, default "ascending"
       Which order to sort values in.
       Accepted values are "ascending", "descending".
   ```



##########
python/pyarrow/table.pxi:
##########
@@ -433,6 +433,22 @@ cdef class ChunkedArray(_PandasConvertible):
 
         return result
 
+    def sort(self, order="ascending"):
+        """
+        Sort the ChunkedArray

Review Comment:
   Should we support the fieldname keyword here as well? (and raise an error in case the type of the ChunkedArray is not a struct)



##########
python/pyarrow/array.pxi:
##########
@@ -2746,6 +2762,29 @@ cdef class StructArray(Array):
         result.validate()
         return result
 
+    def sort(self, order="ascending", fieldname=None):
+        """
+        Sort the StructArray
+
+        Parameters
+        ----------
+        order : "ascending" or "descending"
+            The order of the sorting.
+        fieldname : str or None, default None
+            If to sort the array by one of its fields
+            or by the whole array.
+
+        Returns
+        -------
+        result : StructArray
+        """
+        if fieldname is not None:
+            tosort = self.field(fieldname)

Review Comment:
   We currently don't use "fieldname" anywhere. Maybe just `field` as the keyword argument?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org