Skip to content

Commit

Permalink
sort was raising too too
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jan 9, 2025
1 parent de697e7 commit a0b1ed7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions narwhals/_duckdb/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def sort(
result = self._native_frame.order(
",".join(
(
f"{col} {desc} nulls last"
f'"{col}" {desc} nulls last'
if nulls_last
else f"{col} {desc} nulls first"
else f'"{col}" {desc} nulls first'
for col, desc in zip(flat_by, descending_str)
)
)
Expand Down
16 changes: 8 additions & 8 deletions tests/frame/sort_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@


def test_sort(constructor: Constructor) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
data = {"an tan": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor(data))
result = df.sort("a", "b")
result = df.sort("an tan", "b")
expected = {
"a": [1, 2, 3],
"an tan": [1, 2, 3],
"b": [4, 6, 4],
"z": [7.0, 9.0, 8.0],
}
assert_equal_data(result, expected)
result = df.sort("a", "b", descending=[True, False])
result = df.sort("an tan", "b", descending=[True, False])
expected = {
"a": [3, 2, 1],
"an tan": [3, 2, 1],
"b": [4, 6, 4],
"z": [8.0, 9.0, 7.0],
}
Expand All @@ -29,14 +29,14 @@ def test_sort(constructor: Constructor) -> None:
@pytest.mark.parametrize(
("nulls_last", "expected"),
[
(True, {"a": [0, 2, 0, -1], "b": [3, 2, 1, None]}),
(False, {"a": [-1, 0, 2, 0], "b": [None, 3, 2, 1]}),
(True, {"antan desc": [0, 2, 0, -1], "b": [3, 2, 1, None]}),
(False, {"antan desc": [-1, 0, 2, 0], "b": [None, 3, 2, 1]}),
],
)
def test_sort_nulls(
constructor: Constructor, *, nulls_last: bool, expected: dict[str, float]
) -> None:
data = {"a": [0, 0, 2, -1], "b": [1, 3, 2, None]}
data = {"antan desc": [0, 0, 2, -1], "b": [1, 3, 2, None]}
df = nw.from_native(constructor(data))
result = df.sort("b", descending=True, nulls_last=nulls_last)
assert_equal_data(result, expected)

0 comments on commit a0b1ed7

Please sign in to comment.