Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depr(python): Deprecate nulls_last/maintain_order/multithreaded parameters for top_k methods #16597

Merged
merged 7 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4742,31 +4742,41 @@ def top_k(
*,
by: IntoExpr | Iterable[IntoExpr],
descending: bool | Sequence[bool] = False,
nulls_last: bool = False,
maintain_order: bool = False,
nulls_last: bool | None = None,
maintain_order: bool | None = None,
) -> DataFrame:
"""
Return the `k` largest elements.

If `descending=True` the smallest elements will be given.
Return the `k` largest rows.

Parameters
----------
k
Number of rows to return.
by
Column(s) included in sort order. Accepts expression input.
Strings are parsed as column names.
Column(s) used to determine the top rows.
Accepts expression input. Strings are parsed as column names.
descending
Return the `k` smallest. Top-k by multiple columns can be specified
per column by passing a sequence of booleans.
Consider the `k` smallest elements of the `by` column(s) (instead of the `k`
largest). This can be specified per column by passing a sequence of
booleans.

nulls_last
Place null values last.

.. deprecated:: 0.20.31
This parameter will be removed in the next breaking release.
Null values will be considered lowest priority and will only be
included if `k` is larger than the number of non-null elements.

maintain_order
Whether the order should be maintained if elements are equal.
Note that if `true` streaming is not possible and performance might be
worse since this requires a stable search.

.. deprecated:: 0.20.31
This parameter will be removed in the next breaking release.
There will be no guarantees about the order of the output.

See Also
--------
bottom_k
Expand Down Expand Up @@ -4833,31 +4843,41 @@ def bottom_k(
*,
by: IntoExpr | Iterable[IntoExpr],
descending: bool | Sequence[bool] = False,
nulls_last: bool = False,
maintain_order: bool = False,
nulls_last: bool | None = None,
maintain_order: bool | None = None,
) -> DataFrame:
"""
Return the `k` smallest elements.

If `descending=True` the largest elements will be given.
Return the `k` smallest rows.

Parameters
----------
k
Number of rows to return.
by
Column(s) included in sort order. Accepts expression input.
Strings are parsed as column names.
Column(s) used to determine the bottom rows.
Accepts expression input. Strings are parsed as column names.
descending
Return the `k` largest. Bottom-k by multiple columns can be specified
per column by passing a sequence of booleans.
Consider the `k` largest elements of the `by` column(s) (instead of the `k`
smallest). This can be specified per column by passing a sequence of
booleans.

nulls_last
Place null values last.

.. deprecated:: 0.20.31
This parameter will be removed in the next breaking release.
Null values will be considered lowest priority and will only be
included if `k` is larger than the number of non-null elements.

maintain_order
Whether the order should be maintained if elements are equal.
Note that if `true` streaming is not possible and performance might be
worse since this requires a stable search.

.. deprecated:: 0.20.31
This parameter will be removed in the next breaking release.
There will be no guarantees about the order of the output.

See Also
--------
top_k
Expand Down
Loading