Skip to content

0.10.0 has improper handling of pd.NA values when the dtype is, e.g., float32[pyarrow] #429

@adamroyjones

Description

@adamroyjones

(This is in the same region as code as the AI-generated report #428.)

Here's a(n approximately) minimal reproducing example:

# test_reprex.py
import pytest
import pandas as pd
from tabulate import tabulate


def test_reprex():
    df = pd.DataFrame({"id": ["a"], "x": [pd.NA]}).astype(
        {"id": "string", "x": "float32[pyarrow]"}
    )
    with pytest.raises(TypeError):
        tabulate(df, maxcolwidths=10)

A stack trace:

.venv/lib/python3.11/site-packages/tabulate/__init__.py:2308: in tabulate
    list_of_lists = _wrap_text_to_colwidths(
.venv/lib/python3.11/site-packages/tabulate/__init__.py:1704: in _wrap_text_to_colwidths
    if cell == "" or _isnumber(cell)
       ^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   TypeError: boolean value of NA is ambiguous

This is with Python 3.11.15 and the following packages.

Package         Version
--------------- -----------
iniconfig       2.3.0
numpy           2.4.4
packaging       26.2
pandas          3.0.3
pluggy          1.6.0
pyarrow         24.0.0
pygments        2.20.0
pytest          9.0.3
python-dateutil 2.9.0.post0
ruff            0.15.13
six             1.17.0
tabulate        0.10.0

Please let me know if you need or want more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions