Skip to content

Commit 1caf2e4

Browse files
author
MarcoGorelli
committed
Merge remote-tracking branch 'upstream/main' into concat
2 parents d323908 + c1b1ab1 commit 1caf2e4

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

spec/API_specification/dataframe_api/dataframe_object.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
2-
from typing import Sequence, Union, TYPE_CHECKING, NoReturn, Mapping
2+
3+
from typing import Literal, Mapping, Sequence, Union, TYPE_CHECKING, NoReturn
4+
35

46
if TYPE_CHECKING:
57
from .column_object import Column
@@ -260,6 +262,48 @@ def concat(self, other: Sequence[DataFrame]) -> DataFrame:
260262
-------
261263
DataFrame
262264
"""
265+
...
266+
267+
def sorted_indices(
268+
self,
269+
keys: Sequence[str],
270+
*,
271+
ascending: Sequence[bool] | bool = True,
272+
nulls_position: Literal['first', 'last'] = 'last',
273+
) -> Column[int]:
274+
"""
275+
Return row numbers which would sort according to given columns.
276+
277+
If you need to sort the DataFrame, you can simply do::
278+
279+
df.get_rows(df.sorted_indices(keys))
280+
281+
Parameters
282+
----------
283+
keys : Sequence[str]
284+
Names of columns to sort by.
285+
ascending : Sequence[bool] or bool
286+
If `True`, sort by all keys in ascending order.
287+
If `False`, sort by all keys in descending order.
288+
If a sequence, it must be the same length as `keys`,
289+
and determines the direction with which to use each
290+
key to sort by.
291+
nulls_position : {'first', 'last'}
292+
Whether null values should be placed at the beginning
293+
or at the end of the result.
294+
Note that the position of NaNs is unspecified and may
295+
vary based on the implementation.
296+
297+
Returns
298+
-------
299+
Column[int]
300+
301+
Raises
302+
------
303+
ValueError
304+
If `keys` and `ascending` are sequences of different lengths.
305+
"""
306+
...
263307

264308
def __eq__(self, other: DataFrame | Scalar) -> DataFrame:
265309
"""

0 commit comments

Comments
 (0)