question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aggregate is broken when supplying single key in an array

See original GitHub issue

Minimal, 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:closed
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
juarezrcommented, Jan 5, 2022

@MalayGoel, thanks.

1reaction
juarezrcommented, Dec 31, 2021

Hi @MalayGoel,

Would you mind sending a PR?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found