Skip to content

Commit

Permalink
docs(examples): GroupedTable having example
Browse files Browse the repository at this point in the history
  • Loading branch information
IndexSeek committed Nov 8, 2024
1 parent 72e6f7b commit 686affa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ibis/expr/types/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ def having(self, *predicates: ir.BooleanScalar) -> GroupedTable:
-------
GroupedTable
A grouped table expression
Examples
--------
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {"grouper": ["a", "a", "a", "b", "b", "c"], "values": [1, 2, 3, 1, 2, 1]}
... )
>>> expr = (
... t.group_by(t.grouper)
... .having(t.count() < 3)
... .aggregate(values_count=t.count(), values_sum=t.values.sum())
... )
>>> expr
┏━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ grouper ┃ values_count ┃ values_sum ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ string │ int64 │ int64 │
├─────────┼──────────────┼────────────┤
│ b │ 2 │ 3 │
│ c │ 1 │ 1 │
└─────────┴──────────────┴────────────┘
"""
table = self.table.to_expr()
havings = table.bind(*predicates)
Expand Down

0 comments on commit 686affa

Please sign in to comment.