Skip to content

Commit

Permalink
feat(polars): add argmin and argmax
Browse files Browse the repository at this point in the history
  • Loading branch information
mesejo authored and cpcloud committed May 27, 2023
1 parent 8c67deb commit 78562d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 27 additions & 0 deletions ibis/backends/polars/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,30 @@ def execute_not_any(op, **kwargs):
arg = ops.Where(op_where, arg, None)

return translate(arg).any().is_not()


def _arg_min_max(op, func, **kwargs):
key = op.key
arg = op.arg

if (op_where := op.where) is not None:
key = ops.Where(op_where, key, None)
arg = ops.Where(op_where, arg, None)

translate_arg = translate(arg)
translate_key = translate(key)

not_null_mask = translate_arg.is_not_null() & translate_key.is_not_null()
return translate_arg.filter(not_null_mask).take(
func(translate_key.filter(not_null_mask))
)


@translate.register(ops.ArgMax)
def execute_arg_max(op, **kwargs):
return _arg_min_max(op, pl.Expr.arg_max, **kwargs)


@translate.register(ops.ArgMin)
def execute_arg_min(op, **kwargs):
return _arg_min_max(op, pl.Expr.arg_min, **kwargs)
3 changes: 0 additions & 3 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def mean_udf(s):
"datafusion",
"impala",
"mysql",
"polars",
"mssql",
"druid",
"oracle",
Expand Down Expand Up @@ -459,7 +458,6 @@ def mean_and_std(v):
[
"impala",
"mysql",
"polars",
"datafusion",
"mssql",
"druid",
Expand All @@ -484,7 +482,6 @@ def mean_and_std(v):
[
"impala",
"mysql",
"polars",
"datafusion",
"mssql",
"druid",
Expand Down

1 comment on commit 78562d3

@ibis-squawk-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 3.

Benchmark suite Current: 78562d3 Previous: 8c67deb Ratio
ibis/tests/benchmarks/test_benchmarks.py::test_compile[small-bigquery] 818.8801354981659 iter/sec (stddev: 0.011125520020339619) 7051.453966685956 iter/sec (stddev: 0.00001626957532104326) 8.61

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.