MCPcopy Create free account
hub / github.com/dask/dask / sort_values

Method sort_values

dask/dataframe/dask_expr/_collection.py:3532–3605  ·  view source on GitHub ↗

Sort the dataset by a single column. Sorting a parallel dataset requires expensive shuffles and is generally not recommended. See ``set_index`` for implementation details. Parameters ---------- by: str or list[str] Column(s) to sort by. n

(
        self,
        by: str | list[str],
        npartitions: int | None = None,
        ascending: bool | list[bool] = True,
        na_position: Literal["first", "last"] = "last",
        partition_size: float = 128e6,
        sort_function: Callable[[pd.DataFrame], pd.DataFrame] | None = None,
        sort_function_kwargs: Mapping[str, Any] | None = None,
        upsample: float = 1.0,
        ignore_index: bool | None = False,
        shuffle_method: str | None = None,
        **options,
    )

Source from the content-addressed store, hash-verified

3530 )
3531
3532 def sort_values(
3533 self,
3534 by: str | list[str],
3535 npartitions: int | None = None,
3536 ascending: bool | list[bool] = True,
3537 na_position: Literal["first", "last"] = "last",
3538 partition_size: float = 128e6,
3539 sort_function: Callable[[pd.DataFrame], pd.DataFrame] | None = None,
3540 sort_function_kwargs: Mapping[str, Any] | None = None,
3541 upsample: float = 1.0,
3542 ignore_index: bool | None = False,
3543 shuffle_method: str | None = None,
3544 **options,
3545 ):
3546 """Sort the dataset by a single column.
3547
3548 Sorting a parallel dataset requires expensive shuffles and is generally
3549 not recommended. See ``set_index`` for implementation details.
3550
3551 Parameters
3552 ----------
3553 by: str or list[str]
3554 Column(s) to sort by.
3555 npartitions: int, None, or 'auto'
3556 The ideal number of output partitions. If None, use the same as
3557 the input. If 'auto' then decide by memory use.
3558 ascending: bool, optional
3559 Sort ascending vs. descending.
3560 Defaults to True.
3561 na_position: {'last', 'first'}, optional
3562 Puts NaNs at the beginning if 'first', puts NaN at the end if 'last'.
3563 Defaults to 'last'.
3564 sort_function: function, optional
3565 Sorting function to use when sorting underlying partitions.
3566 If None, defaults to ``M.sort_values`` (the partition library's
3567 implementation of ``sort_values``).
3568 sort_function_kwargs: dict, optional
3569 Additional keyword arguments to pass to the partition sorting function.
3570 By default, ``by``, ``ascending``, and ``na_position`` are provided.
3571
3572 Examples
3573 --------
3574 >>> df2 = df.sort_values('x') # doctest: +SKIP
3575 """
3576 if na_position not in ("first", "last"):
3577 raise ValueError("na_position must be either 'first' or 'last'")
3578 if not isinstance(by, list):
3579 by = [by]
3580 if any(not isinstance(b, str) for b in by):
3581 raise NotImplementedError(
3582 "Dataframes only support sorting by named columns which must be passed as a "
3583 "string or a list of strings.\n"
3584 f"You passed {by}"
3585 )
3586
3587 if not isinstance(ascending, bool) and not len(ascending) == len(by):
3588 raise ValueError(f"Length of {ascending=} != length of {by=}")
3589

Calls 4

new_collectionFunction · 0.90
SortValuesClass · 0.90
get_specified_shuffleFunction · 0.90
anyFunction · 0.85