Repository navigation
Do not crash when the deduced cell type rejects the raw value under maxcolwidths (#359, #448) - #506
Open
thejedi433 wants to merge 1 commit into
Open
thejedi433 wants to merge 1 commit into
thejedi433 wants to merge 1 commit into
Conversation
…axcolwidths
_wrap_text_to_colwidths() classifies a cell with _type() and applies the
returned constructor to the RAW value before wrapping. _type() strips
ANSI escapes and recognizes thousands separators when classifying, but
int()/float() reject those raw strings:
- int("\x1b[31m3\x1b[0m") (issue astanin#359, ANSI-colored numeric string)
- int("1,000") (thousands separator, integer-looking)
- float("1,000.5") (thousands separator, float-looking)
The positional _type(cell, numparse) call also filled has_invisible
instead of numparse, so disable_numparse was silently ignored on this
path and int("100,120") raised (issue astanin#448).
Pass numparse as a keyword and keep the original text when the
constructor refuses the raw value, so wrapped rendering matches
unwrapped rendering instead of crashing.
Fixes astanin#359
Fixes astanin#448
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_wrap_text_to_colwidths()classifies each cell with_type()and then applies the returned constructor to the raw value before wrapping._type()strips ANSI escapes and recognizes thousands separators while classifying, butint()/float()reject those raw strings, somaxcolwidthscrashes on values that render fine without it:Separately, the call
_type(cell, numparse)passes the flag positionally intohas_invisible, sonumparsekeeps its defaultTrueanddisable_numparse=Trueis silently ignored on this path —int("100,120")raises (issue #448, a regression of the #305/#362 fix).Fix
Pass
numparseas a keyword, and keep the original text when the deduced constructor refuses the raw value. Wrapped rendering now matches unwrapped rendering instead of crashing:The
exceptis scoped to the cast only (ValueError/TypeError), so genuine type-deduction behavior is unchanged for every cell the constructors accept (1.50still normalizes to1.5, ints still right-align, etc.).This supersedes #444 (closed; it special-cased ANSI detection instead of handling the cast failure, and covered neither the thousands-separator crash nor the
disable_numparsepositional bug). It includes the keyword-passing fix of #471/#473 as a subset plus the crash-class fixes they do not cover (1,000and colored strings with default numparse still crash with keyword-only passing).Testing
test/test_regression.py, each verified to fail on pristine268615aand pass with the fix.pytest --doctest-modules, Python 3.11/3.13 both exercised via the fork CI matrix).ruff check/ruff format --checkreport no new findings (the 10 pre-existingISC001warnings in the untouched files are unchanged from baseline).Closes #359
Closes #448