Skip to content

Commit b166cdf

Browse files
authored
Add column.sorted_indices (#184)
* add column.sorted_indices * typo
1 parent 04650ba commit b166cdf

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

spec/API_specification/dataframe_api/column_object.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, NoReturn, Sequence, TYPE_CHECKING
3+
from typing import Any,NoReturn, Sequence, TYPE_CHECKING, Literal
44

55
if TYPE_CHECKING:
66
from ._types import Scalar
@@ -98,6 +98,36 @@ def get_value(self, row_number: int) -> Scalar:
9898
"""
9999
...
100100

101+
def sorted_indices(
102+
self,
103+
*,
104+
ascending: bool = True,
105+
nulls_position: Literal['first', 'last'] = 'last',
106+
) -> Column[int]:
107+
"""
108+
Return row numbers which would sort column.
109+
110+
If you need to sort the Column, you can simply do::
111+
112+
col.get_rows(col.sorted_indices())
113+
114+
Parameters
115+
----------
116+
ascending : bool
117+
If `True`, sort in ascending order.
118+
If `False`, sort in descending order.
119+
nulls_position : ``{'first', 'last'}``
120+
Whether null values should be placed at the beginning
121+
or at the end of the result.
122+
Note that the position of NaNs is unspecified and may
123+
vary based on the implementation.
124+
125+
Returns
126+
-------
127+
Column[int]
128+
"""
129+
...
130+
101131
def __eq__(self, other: Column | Scalar) -> Column:
102132
"""
103133
Compare for equality.

0 commit comments

Comments
 (0)