Skip to content

Commit

Permalink
feat(postgres): implement mode aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and cpcloud committed Nov 3, 2022
1 parent 36fd152 commit b2f1c2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ibis/backends/postgres/registry.py
Expand Up @@ -486,6 +486,13 @@ def _covar(t, op):
return _binary_variance_reduction(func)(t, op)


def _mode(t, op):
arg = op.arg
if op.where is not None:
arg = op.where.to_expr().ifelse(arg, None).op()
return sa.func.mode().within_group(t.translate(arg))


def _binary_variance_reduction(func):
def variance_compiler(t, op):
x = op.left
Expand Down Expand Up @@ -590,5 +597,6 @@ def variance_compiler(t, op):
ops.Covariance: _covar,
ops.Correlation: _corr,
ops.BitwiseXor: _bitwise_op("#"),
ops.Mode: _mode,
}
)
1 change: 0 additions & 1 deletion ibis/backends/tests/test_aggregation.py
Expand Up @@ -280,7 +280,6 @@ def mean_and_std(v):
"mysql",
"pandas",
"polars",
"postgres",
"pyspark",
"snowflake",
"sqlite",
Expand Down

0 comments on commit b2f1c2d

Please sign in to comment.