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

fix(python): DataFrame descending sorting by single list element #19233

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,8 @@ def sort(
"""
# Fast path for sorting by a single existing column
if isinstance(by, str) and not more_by:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just not hit the fast path if the user passes a list:

if isinstance(by, str) and isintance(descending, bool) and not more_by:

if isinstance(descending, list):
descending = descending[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check and raise an error if the list length is not 1

return self._from_pyldf(
self._ldf.sort(
by, descending, nulls_last, maintain_order, multithreaded
Expand Down
3 changes: 3 additions & 0 deletions py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def test_sort() -> None:
assert_frame_equal(
df.sort(["a", "b"]), pl.DataFrame({"a": [1, 2, 3], "b": [2, 1, 3]})
)
assert_frame_equal(
df.sort("a", descending=[False]), pl.DataFrame({"a": [1, 2, 3], "b": [2, 1, 3]})
)


def test_sort_multi_output_exprs_01() -> None:
Expand Down