You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve error reporting when tabular_data is a dict of non-iterable values #124
I am trying to tabulate a counter from collections counter
print(tabulate(counter))
this approach gives an error message:
File "/Users/wf/Library/Python/3.8/lib/python/site-packages/tabulate.py", line 1528, in tabulate
list_of_lists, headers = _normalize_tabular_data(
File "/Users/wf/Library/Python/3.8/lib/python/site-packages/tabulate.py", line 1089, in _normalize_tabular_data
izip_longest(*tabular_data.values())
TypeError: 'int' object is not iterable
What else should i do - or would this be a feature request?
I'd like to second this feature request.
It would be great to have built-in support for collectionsCounters, instead of writing my own wrapper function.
When tablefmt='pretty' is set, tabulate appears to be treating each column as if it were a string, prior to applying floatfmt. So no float formatting is being applied, even though the floatfmt parameter is set. As a workaround, you can either not specify tablefmt, or you can apply the format builtin when calculating your data.
@patrickdeanbrown thank you for looking into this. Your workarounds are nice but do not solve the problem/fulfill the need of a simpler interface that this issue is requesting.
Activity
WolfgangFahl commentedon May 3, 2021
This is what it did so far to get my result - unfortunately floatfmt doesn't seem to work:
ivan-radic commentedon May 17, 2021
Hi,
I'd like to second this feature request.
It would be great to have built-in support for
collectionsCounters, instead of writing my own wrapper function.Best regards,
Ivan
patrickdeanbrown commentedon Nov 4, 2021
Hi @WolfgangFahl,
When
tablefmt='pretty'is set, tabulate appears to be treating each column as if it were a string, prior to applyingfloatfmt. So no float formatting is being applied, even though the floatfmt parameter is set. As a workaround, you can either not specify tablefmt, or you can apply the format builtin when calculating your data.As for directly using a Counter object with tabulate, you can call the Counter.items() method, and it should work.
WolfgangFahl commentedon Nov 5, 2021
@patrickdeanbrown thank you for looking into this. Your workarounds are nice but do not solve the problem/fulfill the need of a simpler interface that this issue is requesting.
astanin commentedon Oct 19, 2022
Tabulate can process an iterable (list) of dictionaries. It should work with a list of
Counters too:Using
counter.items()is the intended way to print similar data as rows.>>> print(tabulate(c.items())) - - a 3 b 4 - -astanin commentedon Oct 19, 2022
But the error message can be improved. The library should have suggested what data shape it expects.
[-]tabulate collections counter[/-][+]Improve error reporting when tabular_data is a dict of non-iterable values[/+]Fix astanin#124. Improve error reporting when non-iterable data provi…
Merge pull request #233 from ilya112358/add_msg_when_not_iterable