Groupby API
Contains reference for helper classes related to groupby.
class pw.GroupedJoinResult(*, join_result, args, id)
promise_universe_is_equal_to(other)
Asserts to Pathway that an universe of self is a subset of universe of each of the others.Semantics: Used in situations where Pathway cannot deduce one universe being a subset of another.
- Returns
None
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| pet
1 | Dog
7 | Cat
''')
t2 = pw.debug.parse_to_table('''
| age
1 | 10
7 | 3
''')
t1 = t1.promise_universe_is_equal_to(t2)
t3 = t1 + t2
pw.debug.compute_and_print(t3, include_id=False)
promise_universe_is_subset_of(other)
Asserts to Pathway that an universe of self is a subset of universe of each of the other.Semantics: Used in situations where Pathway cannot deduce one universe being a subset of another.
- Returns
self
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 1
2 | 9 | Bob | 1
3 | 8 | Alice | 2
''')
t2 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 30
''').promise_universe_is_subset_of(t1)
t3 = t1 << t2
pw.debug.compute_and_print(t3, include_id=False)
promise_universes_are_disjoint(other)
Asserts to Pathway that an universe of self is disjoint from universe of other.Semantics: Used in situations where Pathway cannot deduce universes are disjoint.
- Returns
self
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 1
2 | 9 | Bob | 1
3 | 8 | Alice | 2
''')
t2 = pw.debug.parse_to_table('''
| age | owner | pet
11 | 11 | Alice | 30
12 | 12 | Tom | 40
''').promise_universes_are_disjoint(t1)
t3 = t1.concat(t2)
pw.debug.compute_and_print(t3, include_id=False)
reduce(*args, **kwargs)
Reduces grouped join result to table.- Returns
Table – Created table.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
cost owner pet
1 100 Alice 1
2 90 Bob 1
3 80 Alice 2
''')
t2 = pw.debug.parse_to_table('''
cost owner pet size
11 100 Alice 3 M
12 90 Bob 1 L
13 80 Tom 1 XL
''')
result = (t1.join(t2, t1.owner==t2.owner).groupby(pw.this.owner)
.reduce(pw.this.owner, pairs = pw.reducers.count()))
pw.debug.compute_and_print(result, include_id=False)
class pw.GroupedJoinable(_universe, _substitution, _joinable)
promise_universe_is_equal_to(other)
Asserts to Pathway that an universe of self is a subset of universe of each of the others.Semantics: Used in situations where Pathway cannot deduce one universe being a subset of another.
- Returns
None
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| pet
1 | Dog
7 | Cat
''')
t2 = pw.debug.parse_to_table('''
| age
1 | 10
7 | 3
''')
t1 = t1.promise_universe_is_equal_to(t2)
t3 = t1 + t2
pw.debug.compute_and_print(t3, include_id=False)
promise_universe_is_subset_of(other)
Asserts to Pathway that an universe of self is a subset of universe of each of the other.Semantics: Used in situations where Pathway cannot deduce one universe being a subset of another.
- Returns
self
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 1
2 | 9 | Bob | 1
3 | 8 | Alice | 2
''')
t2 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 30
''').promise_universe_is_subset_of(t1)
t3 = t1 << t2
pw.debug.compute_and_print(t3, include_id=False)
promise_universes_are_disjoint(other)
Asserts to Pathway that an universe of self is disjoint from universe of other.Semantics: Used in situations where Pathway cannot deduce universes are disjoint.
- Returns
self
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 1
2 | 9 | Bob | 1
3 | 8 | Alice | 2
''')
t2 = pw.debug.parse_to_table('''
| age | owner | pet
11 | 11 | Alice | 30
12 | 12 | Tom | 40
''').promise_universes_are_disjoint(t1)
t3 = t1.concat(t2)
pw.debug.compute_and_print(t3, include_id=False)
class pw.GroupedTable(table, grouping_columns, set_id=False)
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
age | owner | pet
10 | Alice | dog
9 | Bob | dog
8 | Alice | cat
7 | Bob | dog
''')
t2 = t1.groupby(t1.pet, t1.owner)
isinstance(t2, pw.GroupedTable)
promise_universe_is_equal_to(other)
Asserts to Pathway that an universe of self is a subset of universe of each of the others.Semantics: Used in situations where Pathway cannot deduce one universe being a subset of another.
- Returns
None
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| pet
1 | Dog
7 | Cat
''')
t2 = pw.debug.parse_to_table('''
| age
1 | 10
7 | 3
''')
t1 = t1.promise_universe_is_equal_to(t2)
t3 = t1 + t2
pw.debug.compute_and_print(t3, include_id=False)
promise_universe_is_subset_of(other)
Asserts to Pathway that an universe of self is a subset of universe of each of the other.Semantics: Used in situations where Pathway cannot deduce one universe being a subset of another.
- Returns
self
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 1
2 | 9 | Bob | 1
3 | 8 | Alice | 2
''')
t2 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 30
''').promise_universe_is_subset_of(t1)
t3 = t1 << t2
pw.debug.compute_and_print(t3, include_id=False)
promise_universes_are_disjoint(other)
Asserts to Pathway that an universe of self is disjoint from universe of other.Semantics: Used in situations where Pathway cannot deduce universes are disjoint.
- Returns
self
NOTE: The assertion works in place.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
| age | owner | pet
1 | 10 | Alice | 1
2 | 9 | Bob | 1
3 | 8 | Alice | 2
''')
t2 = pw.debug.parse_to_table('''
| age | owner | pet
11 | 11 | Alice | 30
12 | 12 | Tom | 40
''').promise_universes_are_disjoint(t1)
t3 = t1.concat(t2)
pw.debug.compute_and_print(t3, include_id=False)
reduce(*args, **kwargs)
Reduces grouped table to a table.- Parameters
- args (
ColumnReference
) – Column references. - kwargs (
ColumnExpression
) – Column expressions with their new assigned names.
- args (
- Returns
Table – Created table.
Example:
import pathway as pw
t1 = pw.debug.parse_to_table('''
age | owner | pet
10 | Alice | dog
9 | Bob | dog
8 | Alice | cat
7 | Bob | dog
''')
t2 = t1.groupby(t1.pet, t1.owner).reduce(t1.owner, t1.pet, ageagg=pw.reducers.sum(t1.age))
pw.debug.compute_and_print(t2, include_id=False)