Skip to content

Commit 130e4d5

Browse files
authored
docs(examples): add having example for GroupedTable (#10457)
<!-- Thanks for taking the time to contribute to Ibis! Please ensure that your pull request title matches the conventional commits specification: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Description of changes This adds a [`having`](https://ibis-project.org/reference/expression-tables#ibis.expr.types.groupby.GroupedTable.having) example for usage on a `GroupedTable`. I followed it up with an `aggregation` to show the removal of the "a" rows. It could be useful also to show the `having` method without aggregation results in a `GroupedTable,` but I wasn't 100% sure if that would be worth showing.
1 parent 72e6f7b commit 130e4d5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ibis/expr/types/groupby.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ def having(self, *predicates: ir.BooleanScalar) -> GroupedTable:
8282
-------
8383
GroupedTable
8484
A grouped table expression
85+
86+
Examples
87+
--------
88+
>>> import ibis
89+
>>> ibis.options.interactive = True
90+
>>> t = ibis.memtable(
91+
... {"grouper": ["a", "a", "a", "b", "b", "c"], "values": [1, 2, 3, 1, 2, 1]}
92+
... )
93+
>>> expr = (
94+
... t.group_by(t.grouper)
95+
... .having(t.count() < 3)
96+
... .aggregate(values_count=t.count(), values_sum=t.values.sum())
97+
... .order_by(t.grouper)
98+
... )
99+
>>> expr
100+
┏━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
101+
┃ grouper ┃ values_count ┃ values_sum ┃
102+
┡━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
103+
│ string │ int64 │ int64 │
104+
├─────────┼──────────────┼────────────┤
105+
│ b │ 2 │ 3 │
106+
│ c │ 1 │ 1 │
107+
└─────────┴──────────────┴────────────┘
85108
"""
86109
table = self.table.to_expr()
87110
havings = table.bind(*predicates)

0 commit comments

Comments
 (0)