Skip to content

Commit

Permalink
Bugfix: Calling count with None arguments (#768)
Browse files Browse the repository at this point in the history
* Small bugfix. When arguments are None, we should use count_star

* When no arguments are given to count, set argument to lit(1) so that it is similar to count_star but still enables you to select distinct=True.
  • Loading branch information
timsaucer authored Aug 1, 2024
1 parent f580155 commit 66bfe36
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/datafusion/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ def corr(value1: Expr, value2: Expr, distinct: bool = False) -> Expr:

def count(args: Expr | list[Expr] | None = None, distinct: bool = False) -> Expr:
"""Returns the number of rows that match the given arguments."""
if args is None:
return count(Expr.literal(1), distinct=distinct)
if isinstance(args, list):
args = [arg.expr for arg in args]
elif isinstance(args, Expr):
Expand Down

0 comments on commit 66bfe36

Please sign in to comment.