Skip to content

Fix crash when wrapping a pandas NA scalar (#429) - #522

Open
lee3Q wants to merge 2 commits into
astanin:masterfrom
lee3Q:fix/wrap-pandas-na-maxcolwidths
Open

lee3Q wants to merge 2 commits into
astanin:masterfrom
lee3Q:fix/wrap-pandas-na-maxcolwidths

Conversation

@lee3Q

@lee3Q lee3Q commented Dec 2, 2026

Copy link
Copy Markdown

Fixes #429. Supersedes #432, which has the same source fix by @binggao1230 (credited as co-author on the commits).

_wrap_text_to_colwidths checked cell == "" for every cell. For a pandas pd.NA that comparison returns NA, and its truthiness raises TypeError: boolean value of NA is ambiguous, so any table with maxcolwidths and a pd.NA cell crashed. The check now only compares strings, so pd.NA goes through the normal path and is rendered as <NA>, the same as without maxcolwidths.

The test differs from the one in #432: that test expects a blank cell, but the cell is rendered as <NA>, so it fails with the fix applied. The new test expects <NA> and also compares the wrapped and unwrapped output.

The full test suite passes, including the new test, and ruff check and ruff format --check are clean.

lee3Q and others added 2 commits December 2, 2026 12:42
Supersedes astanin#432.

Co-authored-by: Vincent Gao <gaobing1230@gmail.com>
Supersedes astanin#432.

Co-authored-by: Vincent Gao <gaobing1230@gmail.com>
@binggao1230

Copy link
Copy Markdown

Thanks for the credit. One correction to the PR description: #432 already expects <NA> in test_wrap_pandas_na_value, and I reran that exact test at 6fba6ef with pandas 3.1.2; it passes. The additional coverage here is the wrapped-versus-unwrapped equality assertion.

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

Successfully merging this pull request may close these issues.

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

2 participants