Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not tabulate table with pd.NA #239

Open
mscanlon-exos opened this issue Jan 13, 2023 · 2 comments
Open

Can not tabulate table with pd.NA #239

mscanlon-exos opened this issue Jan 13, 2023 · 2 comments

Comments

@mscanlon-exos
Copy link

When moving to 0.9.0, you will see

 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../<my_code>
    return tabulate(
../../../.venv/lib/python3.10/site-packages/tabulate/__init__.py:2048: in tabulate
    list_of_lists, headers = _normalize_tabular_data(
../../../.venv/lib/python3.10/site-packages/tabulate/__init__.py:1471: in _normalize_tabular_data
    rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
../../../.venv/lib/python3.10/site-packages/tabulate/__init__.py:1471: in <lambda>
    rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

when trying to tabulate a pandas dataframe with pd.NA values in the rows

@buhtz
Copy link

buhtz commented Jan 20, 2023

It seems that this is my Issue, too. The folks at pandas asked to to report that Issue here.

Reproduce with

df = pandas.DataFrame([[pandas.NA]])
tabulate.tabulate(df)

The full report including version infos can be found here:
pandas-dev/pandas#50866

It seems that the error happens with tabulate 0.9 but not with 0.8.10.

@ilya112358
Copy link
Contributor

The trouble comes from how pandas.NA propagates itself in cases when you normally expect a boolean:

>>> a = (pandas.NA == "")
>>> a
<NA>
>>> b = (True and a)
>>> b
<NA>
>>> if b:
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas\_libs\missing.pyx", line 382, in pandas._libs.missing.NAType.__bool__
TypeError: boolean value of NA is ambiguous

There is already a pull request #232 for separating lines which fixes this issue as well:

>>> df = pandas.DataFrame([[pandas.NA]])
>>> print(tabulate(df))
-  ----
0  <NA>
-  ----

Let's hope it's merged before long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants