Skip to content

Commit

Permalink
Grouping no longer maintains order.
Browse files Browse the repository at this point in the history
Test fix to not rely on ordering: apache/arrow#36709. Distinct aggregation supports aliasing.
  • Loading branch information
coady committed Jul 18, 2023
1 parent 412cc0a commit 3cc9a6b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions graphique/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ def group(
for agg in aggs['list']:
columns[agg.name] = ListChunk.inner_flatten(*columns[agg.name].chunks)
for agg in distinct:
column = columns[agg.name]
columns[agg.name] = ListChunk.map_list(column, agg.distinct, **agg.options)
column = columns[agg.alias]
columns[agg.alias] = ListChunk.map_list(column, agg.distinct, **agg.options)
return type(self)(self.apply_list(pa.table(columns), list_func))

@strawberry.field(deprecation_reason="use `group(by: [<fragment key>, ...])`")
Expand Down
4 changes: 1 addition & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def test_chunks():
array = pa.chunked_array([list('aba'), list('bcb')])
table = pa.table({'col': array})
groups = T.group(table, 'col', counts='counts')
assert groups['col'].to_pylist() == list('abc')
assert groups['counts'].to_pylist() == [2, 3, 1]
assert table['col'].unique() == pa.array('abc')
assert dict(zip(*groups.to_pydict().values())) == {'a': 2, 'b': 3, 'c': 1}
array = pa.chunked_array([pa.array(list(chunk)).dictionary_encode() for chunk in ('aba', 'ca')])
assert C.index(array, 'a') == 0
assert C.index(array, 'c') == 3
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def test_list(partclient):
)
assert data['group']['tables'][0] == {'length': 1, 'row': {'state': 'PR', 'county': 'Adjuntas'}}
data = partclient.execute(
'''{ group(by: "state", aggregate: {distinct: {name: "county"}}) {
tables { row { state } columns { county { length } } } } }'''
'''{ group(by: "state", aggregate: {distinct: {alias: "counties", name: "county"}}) {
tables { row { state } column(name: "counties") { length } } } } '''
)
table = data['group']['tables'][0]
assert table == {'row': {'state': 'PR'}, 'columns': {'county': {'length': 78}}}
assert table == {'row': {'state': 'PR'}, 'column': {'length': 78}}
data = partclient.execute(
'''{ group(by: "north", aggregate: {distinct: {name: "west"}}) {
tables { row { north } columns { west { length } } } } }'''
Expand Down

0 comments on commit 3cc9a6b

Please sign in to comment.