diff --git a/py-polars/polars/lazyframe/frame.py b/py-polars/polars/lazyframe/frame.py index d5c56c93ca0a..ad513bc1ff55 100644 --- a/py-polars/polars/lazyframe/frame.py +++ b/py-polars/polars/lazyframe/frame.py @@ -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 diff --git a/py-polars/tests/unit/dataframe/test_df.py b/py-polars/tests/unit/dataframe/test_df.py index 015b64ce6303..29856bf3eb4e 100644 --- a/py-polars/tests/unit/dataframe/test_df.py +++ b/py-polars/tests/unit/dataframe/test_df.py @@ -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: