feat(rust,python): reworked comfy-table layout constraints, improving table wrapping/repr #9744
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.
Ref: #9656.
The 7.x
comfy-table
update has turned into a good opportunity to improve our table layout/constraints. Previously the only column width/wrapping constraint that we applied came from a lower bound based on the column name/header.This PR significantly improves constraint application by considering not only the column name, but also the dtype string/sep (if not hidden) and all of the actual (displayed|/formatted) column data. It then uses this more detailed per-column info to apply an exact bound for especially narrow columns (eg: where all elements <= 3 chars), and a combined upper/lower bound for all other columns.
During width bucket allocation for each column (by
comfy-table
during table creation) the presence of exact/upper bounds prevents characters from being over-allocated to columns that don't require them, reducing instances of premature/unnecessary wrapping by better-allocating the character/width budget.With this in place we can now upgrade to the latest
comfy-table
, which slightly tweaked lower-bound application...Example
Simple example showing the impact of more accurate column width determination: