Skip to content

Commit

Permalink
feat(api): count nulls with topk
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `expr.topk(...)` now includes null counts. The row count of the `topk` call will not differ, but the number of nulls counted will no longer be zero. To drop the `null` row use the `dropna` method.
  • Loading branch information
cpcloud committed Mar 3, 2024
1 parent e8bc3b9 commit b67bbc2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,11 @@ def topk(
raise com.IbisTypeError("TopK must depend on exactly one table.")

table = table.to_expr()

if by is None:
metric = self.count()
else:
(metric,) = bind(table, by)
by = lambda t: t.count()

(metric,) = bind(table, by)

return table.aggregate(metric, by=[self]).order_by(metric.desc()).limit(k)

Expand Down

0 comments on commit b67bbc2

Please sign in to comment.