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

Tabulate raises ValueError with np.array as cell values #339

Open
luxedo opened this issue Sep 2, 2024 · 1 comment
Open

Tabulate raises ValueError with np.array as cell values #339

luxedo opened this issue Sep 2, 2024 · 1 comment

Comments

@luxedo
Copy link

luxedo commented Sep 2, 2024

Follow up to: pandas-dev/pandas#59588

tabulate can handle lists [1, 2] as cell values but not numpy arrays np.array([1, 2]):

>>> print(tabulate([[[1, 2], 3]]))
------  -
[1, 2]  3
------  -
>>> print(tabulate([[np.array([1, 2]), 3]]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/john/GitHub/os/envs/numpy/lib/python3.12/site-packages/tabulate/__init__.py", line 2048, in tabulate
    list_of_lists, headers = _normalize_tabular_data(
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/GitHub/os/envs/numpy/lib/python3.12/site-packages/tabulate/__init__.py", line 1471, in _normalize_tabular_data
    rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/GitHub/os/envs/numpy/lib/python3.12/site-packages/tabulate/__init__.py", line 1471, in <lambda>
    rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
                                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/john/GitHub/os/envs/numpy/lib/python3.12/site-packages/tabulate/__init__.py", line 107, in _is_separating_line
    (len(row) >= 1 and row[0] == SEPARATING_LINE)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I'd expect a similar behavior or at least something like:

----------------  -
np.array([1, 2])  3
----------------  -
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

2 participants