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
Bug: intfmt error for strings which contain integer values
Description
The argument intfmt throws an error when some value in the data is a string, but it looks like an integer. For example: the string value “1234” is considering for the _format function as an integer, but it is a string.
Not works: print(tabulate([("1", 9200), ("2", 90000)], intfmt=","))
Works, but not the optimal solution when have plenty of data: print(tabulate([("1", 9200), ("2", 90000)], intfmt=("", ",")))
Error
Traceback (most recent call last):
File "…/main.py", line 58, in <module>
main()
File "…/main.py", line 40, in main
print(tabulate([("1", 9200), ("2", 90000)], intfmt=","))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "…/python3.11/site-packages/tabulate/__init__.py", line 2156, in tabulate
cols = [
^
File "…/python3.11/site-packages/tabulate/__init__.py", line 2157, in <listcomp>
[_format(v, ct, fl_fmt, int_fmt, miss_v, has_invisible) for v in c]
File "…/python3.11/site-packages/tabulate/__init__.py", line 2157, in <listcomp>
[_format(v, ct, fl_fmt, int_fmt, miss_v, has_invisible) for v in c]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "…/python3.11/site-packages/tabulate/__init__.py", line 1222, in _format
return format(val, intfmt)
^^^^^^^^^^^^^^^^^^^
ValueError: Cannot specify ',' with 's'.
airvzxf
changed the title
intfmt: error for strings which contain integer values.
Bug: intfmt error for strings which contain integer values
Apr 14, 2024
As soon a new release is deployed with the pull request #319 changes, as soon I'll test this using pip install tabulate. If it works, I'll close this issue; otherwise I'll add more comments.
Bug:
intfmt
error for strings which contain integer valuesDescription
The argument
intfmt
throws an error when some value in the data is a string, but it looks like an integer. For example: the string value “1234” is considering for the_format
function as an integer, but it is a string.Examples
Works:
print(tabulate([["a", 9200], ["b", 90000]], intfmt=","))
Not works:
print(tabulate([("1", 9200), ("2", 90000)], intfmt=","))
Works, but not the optimal solution when have plenty of data:
print(tabulate([("1", 9200), ("2", 90000)], intfmt=("", ",")))
Error
Debugging
I added the follow prints to debug the error.
When it works
print(tabulate([["a", 9200], ["b", 90000]], intfmt=","))
When it doesn't work
print(tabulate([("1", 9200), ("2", 90000)], intfmt=","))
Noticed that the
val
argument is a string, but thevaltype
is an integer. So, if it tries to execute the:It will throw an error because it is a string trying to format as an integer.
The text was updated successfully, but these errors were encountered: