Skip to content

Commit

Permalink
fix(api): support filter on literal followed by aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and cpcloud committed Apr 5, 2023
1 parent e11de3f commit 68d65c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ibis/expr/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ def shares_some_roots(exprs, parents):
# unique table dependencies of exprs and parents
exprs_deps = set(g.traverse(_find_projections, exprs))
parents_deps = set(g.traverse(_find_projections, parents))
return bool(exprs_deps & parents_deps)
# Also return True if exprs has no roots (e.g. literal-only expressions)
return bool(exprs_deps & parents_deps) or not exprs_deps


def flatten_predicate(node):
Expand Down
6 changes: 6 additions & 0 deletions ibis/tests/expr/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,12 @@ def test_filter_aggregate_pushdown_predicate(table):
assert_equal(filtered, expected)


def test_filter_on_literal_then_aggregate(table):
# Mostly just a smoketest, this used to error on construction
expr = table.filter(ibis.literal(True)).agg(lambda t: t.a.sum().name("total"))
assert expr.columns == ["total"]


@pytest.mark.parametrize(
"case_fn",
[
Expand Down

0 comments on commit 68d65c8

Please sign in to comment.