Aggregate is broken when supplying single key in an array
See original GitHub issueMinimal, reproducible code sample, a copy-pastable example if possible
import petl
table1 = [['foo', 'bar'],
['aaa', 1],
['aaa', 2],
['bbb', 3],
['bbb', 4],
['bbb', 5],
['ccc', 6]]
table2 = petl.aggregate(table1, key=["foo", ], aggregation=len)
print(table2)
"""
+-----+-------+---+---+
| foo | value | | |
+=====+=======+===+===+
| a | a | a | 2 |
+-----+-------+---+---+
| b | b | b | 3 |
+-----+-------+---+---+
| c | c | c | 1 |
+-----+-------+---+---+
"""
Problem description
Seems that iteration is broken somewhere inside aggregation when a key is supplied as a single element of a list. Happened upon it while using key programmatically and the user supplied a single value.
At the very least, should error/fail instead of acting this unpredictably.
Thanks for looking into it 😃
Version and installation information
petl.__version__ == 1.7.4
Python 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0] on linux
- Installed via pip into virtual environment
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Get key, value aggregation of values within an array using ...
I'm trying to implement a query across my db that returns a mapping of each tag and a count of how many times...
Read more >Aggregation and Grouping | Python Data Science Handbook
The split step involves breaking up and grouping a DataFrame depending on the value of the specified key. The apply step involves computing...
Read more >How to include another key in array object into array aggregate
I get difficult to add key into the aggregate from array object here is the data which I want to aggregate // COMPANY...
Read more >4. Working with Key/Value Pairs - Learning Spark [Book]
For example, pair RDDs have a reduceByKey() method that can aggregate data separately for each key, and a join() method that can merge...
Read more >Arrays
and how and when to use array aggregate functions. ... single dimensional arrays, created by passing a value of 1 to the ArrayNew()...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MalayGoel, thanks.
Hi @MalayGoel,
Would you mind sending a PR?