Skip to content

Add column.sorted_indices #184

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

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion spec/API_specification/dataframe_api/column_object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, NoReturn, Sequence, TYPE_CHECKING
from typing import Any,NoReturn, Sequence, TYPE_CHECKING, Literal

if TYPE_CHECKING:
from ._types import Scalar
Expand Down Expand Up @@ -98,6 +98,36 @@ def get_value(self, row_number: int) -> Scalar:
"""
...

def sorted_indices(
self,
*,
ascending: bool = True,
nulls_position: Literal['first', 'last'] = 'last',
) -> Column[int]:
"""
Return row numbers which would sort column.

If you need to sort the Column, you can simply do::

col.get_rows(col.sorted_indices())

Parameters
----------
ascending : bool
If `True`, sort in ascending order.
If `False`, sort in descending order.
nulls_position : ``{'first', 'last'}``
Whether null values should be placed at the beginning
or at the end of the result.
Note that the position of NaNs is unspecified and may
vary based on the implementation.

Returns
-------
Column[int]
"""
...

def __eq__(self, other: Column | Scalar) -> Column:
"""
Compare for equality.
Expand Down