Skip to content

Commit cbb6358

Browse files
authored
chore: use descending and nulls_last for duckdb window_expression (#2791)
1 parent a9f54b3 commit cbb6358

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

narwhals/_duckdb/utils.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ def generate_partition_by_sql(*partition_by: str | Expression) -> str:
304304

305305

306306
def generate_order_by_sql(
307-
*order_by: str | Expression, ascending: bool, nulls_first: bool
307+
*order_by: str | Expression, descending: bool, nulls_last: bool
308308
) -> str:
309309
if not order_by:
310310
return ""
311-
nulls = "nulls first" if nulls_first else "nulls last"
312-
if ascending:
313-
by_sql = ", ".join([f"{parse_into_expression(x)} asc {nulls}" for x in order_by])
314-
else:
311+
nulls = "nulls last" if nulls_last else "nulls first"
312+
if descending:
315313
by_sql = ", ".join([f"{parse_into_expression(x)} desc {nulls}" for x in order_by])
314+
else:
315+
by_sql = ", ".join([f"{parse_into_expression(x)} asc {nulls}" for x in order_by])
316316
return f"order by {by_sql}"
317317

318318

@@ -335,9 +335,7 @@ def window_expression(
335335
msg = f"DuckDB>=1.3.0 is required for this operation. Found: DuckDB {duckdb.__version__}"
336336
raise NotImplementedError(msg) from exc
337337
pb = generate_partition_by_sql(*partition_by)
338-
ob = generate_order_by_sql(
339-
*order_by, ascending=not descending, nulls_first=not nulls_last
340-
)
338+
ob = generate_order_by_sql(*order_by, descending=descending, nulls_last=nulls_last)
341339

342340
if rows_start and rows_end:
343341
rows = f"rows between {rows_start} and {rows_end}"

0 commit comments

Comments
 (0)