|
1 | 1 | 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 | + |
3 | 5 |
|
4 | 6 | if TYPE_CHECKING:
|
5 | 7 | from .column_object import Column
|
@@ -239,6 +241,47 @@ def get_column_names(self) -> Sequence[str]:
|
239 | 241 | """
|
240 | 242 | ...
|
241 | 243 |
|
| 244 | + def sorted_indices( |
| 245 | + self, |
| 246 | + keys: Sequence[str], |
| 247 | + *, |
| 248 | + ascending: Sequence[bool] | bool = True, |
| 249 | + nulls_position: Literal['first', 'last'] = 'last', |
| 250 | + ) -> Column[int]: |
| 251 | + """ |
| 252 | + Return row numbers which would sort according to given columns. |
| 253 | +
|
| 254 | + If you need to sort the DataFrame, you can simply do:: |
| 255 | +
|
| 256 | + df.get_rows(df.sorted_indices(keys)) |
| 257 | +
|
| 258 | + Parameters |
| 259 | + ---------- |
| 260 | + keys : Sequence[str] |
| 261 | + Names of columns to sort by. |
| 262 | + ascending : Sequence[bool] or bool |
| 263 | + If `True`, sort by all keys in ascending order. |
| 264 | + If `False`, sort by all keys in descending order. |
| 265 | + If a sequence, it must be the same length as `keys`, |
| 266 | + and determines the direction with which to use each |
| 267 | + key to sort by. |
| 268 | + nulls_position : {'first', 'last'} |
| 269 | + Whether null values should be placed at the beginning |
| 270 | + or at the end of the result. |
| 271 | + Note that the position of NaNs is unspecified and may |
| 272 | + vary based on the implementation. |
| 273 | +
|
| 274 | + Returns |
| 275 | + ------- |
| 276 | + Column[int] |
| 277 | + |
| 278 | + Raises |
| 279 | + ------ |
| 280 | + ValueError |
| 281 | + If `keys` and `ascending` are sequences of different lengths. |
| 282 | + """ |
| 283 | + ... |
| 284 | + |
242 | 285 | def __eq__(self, other: DataFrame | Scalar) -> DataFrame:
|
243 | 286 | """
|
244 | 287 | Compare for equality.
|
|
0 commit comments