Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-14656: [Python] Add sorting for StructArray#14369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
546825d53fd8c70fe7ed49aa0787e27fb3aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1402,6 +1402,22 @@ cdef class Array(_PandasConvertible): | ||
| """ | ||
| return _pc().index(self, value, start, end, memory_pool=memory_pool) | ||
| def sort(self, order="ascending"): | ||
| """ | ||
| Sort the Array | ||
| Parameters | ||
| ---------- | ||
| order : "ascending" or "descending" | ||
| The order of the sorting. | ||
| Returns | ||
| ------- | ||
| result : Array | ||
| """ | ||
| indices = _pc().sort_indices(self, sort_keys=[("", order)]) | ||
| return self.take(indices) | ||
| def _to_pandas(self, options, types_mapper=None, **kwargs): | ||
| return _array_like_to_pandas(self, options, types_mapper=types_mapper) | ||
| @@ -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. | ||
amol- marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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) | ||
Comment on lines
+2781
to
+2782
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We currently don't use "fieldname" anywhere. Maybe just Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||
| else: | ||
| tosort = self | ||
| indices = _pc().sort_indices(tosort, sort_keys=[("", order)]) | ||
| return self.take(indices) | ||
| cdef class ExtensionArray(Array): | ||
| """ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -433,6 +433,22 @@ cdef class ChunkedArray(_PandasConvertible): | ||
| return result | ||
| def sort(self, order="ascending"): | ||
| """ | ||
| Sort the ChunkedArray | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we support the fieldname keyword here as well? (and raise an error in case the type of the ChunkedArray is not a struct) Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's indeed a general issue that ChunkedArray can be annoying when working with a type that type-specific methods on the array (that's not only for StructArray) | ||
| Parameters | ||
| ---------- | ||
| order : "ascending" or "descending" | ||
| The order of the sorting. | ||
| Returns | ||
| ------- | ||
| result : ChunkedArray | ||
| """ | ||
| indices = _pc().sort_indices(self, sort_keys=[("", order)]) | ||
| return self.take(indices) | ||
| def _to_pandas(self, options, types_mapper=None, **kwargs): | ||
| return _array_like_to_pandas(self, options, types_mapper=types_mapper) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.