Fix #135. Get rid of exceptions when converting values to numbers.
Fix #135
- [x] Add the test to check for exceptions
- [x] Fix for booleans to float conversion
- [x] Fix for booleans and strings formatted as integers
- [x] Recognize ansi colors for booleans and integers
- [x] Improve readability
Note: there is (and has been for a while as I understand it) an inconsistency in boolean representation in the columns which contain a mix of bools and numbers. Booleans were passed as text in case of unformatted integer column type, and converted into [0, 1] otherwise. For example:
>>> print(tabulate([[1.1, 1], [True, True]]))
--- ----
1.1 1
1 True
--- ----
This behavior is PRESERVED in the current fix, no breaking changes introduced, just "True" and True are handled in the same way now.
This pull request also fixes another issue (see below).
So, another issue is that ansi color codes are recognized only for floats. Presumably, it doesn't matter for nones, strings and bytes but in case of bools and integers this leads to the same kind of exceptions.
>>> print(tabulate([[1000, 1.1],['\033[31m1000\033[0m', '\033[31mTrue\033[0m']], intfmt=','))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 2176, in tabulate
cols = [
^
File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 2177, in <listcomp>
[_format(v, ct, fl_fmt, int_fmt, miss_v, has_invisible) for v in c]
File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 2177, in <listcomp>
[_format(v, ct, fl_fmt, int_fmt, miss_v, has_invisible) for v in c]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 1231, in _format
return format(val, intfmt)
^^^^^^^^^^^^^^^^^^^
ValueError: Cannot specify ',' with 's'.
This should be fixed now.

Running into the same issue--can we please get a review for this PR? 🙏
Please PR this, I have the same issue here (#289)
+1 on making this fix. Can we get a review?