petl-developers / petl

Python Extract Transform and Load Tables of Data
MIT License
1.22k stars 189 forks source link

Valuecounter FIeldSelectionError when field selector is a tuple #641

Open zuzanna-maria opened 1 year ago

zuzanna-maria commented 1 year ago

Like it says in the title - trying to reproduce the example use for ValueCounter given in docs, works fine if field is given as single name/index, throws 'Unprintable FieldSelectionError' when trying to provide field argument as tuple.

juarezr commented 1 year ago

Do you have a simple code snippet to speed up reproducing the bug and also for adding an automated test case for avoiding further regression?

zuzanna-maria commented 1 year ago

The code snippet I used is the one provided in the documentation.

juarezr commented 1 year ago

Not sure where the problem is exactly. I noticed that field is a *args non-named list parameter instead of a tuple parameter. So this should fail:

import petl as etl
table = [['foo', 'bar'],
        ['a', 1, 1],
        ['b', 2, 2],
        ['b', 2, 3],
        ['b', 3, 3],
        ['c', 4, 4]]

some_fields = ( 'foo', 'bar' )

ok = etl.valuecounter(table, 'foo', 'bar' )

ok = etl.valuecounter(table, *some_fields )  # notice the * deconstruction operator

fails = etl.valuecounter(table, some_fields )

Is this the case?