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

Method sort_values

dask/dataframe/dask_expr/_collection.py:3528–3601  ·  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

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

Calls 4

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