Skip to content

Commit

Permalink
fix(python): DataFrame descending sorting by single list element (pol…
Browse files Browse the repository at this point in the history
  • Loading branch information
khalidmammadov authored Oct 18, 2024
1 parent a3401dc commit da8e37a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 6 additions & 1 deletion py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,12 @@ def sort(
└──────┴─────┴─────┘
"""
# Fast path for sorting by a single existing column
if isinstance(by, str) and not more_by:
if (
isinstance(by, str)
and not more_by
and isinstance(descending, bool)
and isinstance(nulls_last, bool)
):
return self._from_pyldf(
self._ldf.sort(
by, descending, nulls_last, maintain_order, multithreaded
Expand Down
7 changes: 3 additions & 4 deletions py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,9 @@ def test_dataframe_membership_operator() -> None:

def test_sort() -> None:
df = pl.DataFrame({"a": [2, 1, 3], "b": [1, 2, 3]})
assert_frame_equal(df.sort("a"), pl.DataFrame({"a": [1, 2, 3], "b": [2, 1, 3]}))
assert_frame_equal(
df.sort(["a", "b"]), pl.DataFrame({"a": [1, 2, 3], "b": [2, 1, 3]})
)
expected = pl.DataFrame({"a": [1, 2, 3], "b": [2, 1, 3]})
assert_frame_equal(df.sort("a"), expected)
assert_frame_equal(df.sort(["a", "b"]), expected)


def test_sort_multi_output_exprs_01() -> None:
Expand Down

0 comments on commit da8e37a

Please sign in to comment.