Skip to content

Commit

Permalink
chore: support nulls_first in pandas and dask
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi committed Jun 21, 2024
1 parent 2f805c8 commit be221d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ibis/backends/dask/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,14 @@ def visit(cls, op: ops.Sort, parent, keys):
# 2. sort the dataframe using those columns
# 3. drop the sort key columns
ascending = [key.ascending for key in op.keys]
na_pos_dict = {True: "first", False: "last"}
na_position = na_pos_dict[all(key.nulls_first for key in op.keys)]
nulls_first = [key.nulls_first for key in op.keys]

if all(nulls_first):
na_position = "first"
elif not any(nulls_first):
na_position = "last"
else:
raise ValueError("dask does not support different columns ordering")

Check warning on line 374 in ibis/backends/dask/executor.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/dask/executor.py#L374

Added line #L374 was not covered by tests

newcols = {gen_name("sort_key"): col for col in keys}
names = list(newcols.keys())
Expand Down
10 changes: 8 additions & 2 deletions ibis/backends/pandas/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,14 @@ def visit(cls, op: ops.Sort, parent, keys):
# 2. sort the dataframe using those columns
# 3. drop the sort key columns
ascending = [key.ascending for key in op.keys]
na_pos_dict = {True: "first", False: "last"}
na_position = na_pos_dict[all(key.nulls_first for key in op.keys)]
nulls_first = [key.nulls_first for key in op.keys]

if all(nulls_first):
na_position = "first"
elif not any(nulls_first):
na_position = "last"
else:
raise ValueError("pandas does not support different columns ordering")

Check warning on line 603 in ibis/backends/pandas/executor.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pandas/executor.py#L603

Added line #L603 was not covered by tests

newcols = {gen_name("sort_key"): col for col in keys}
names = list(newcols.keys())
Expand Down

0 comments on commit be221d4

Please sign in to comment.