Skip to content

Respect floatfmt and intfmt in the pretty format - #497

Open
DresdenGman wants to merge 1 commit into
astanin:masterfrom
DresdenGman:fix-71-pretty-floatfmt
Open

DresdenGman wants to merge 1 commit into
astanin:masterfrom
DresdenGman:fix-71-pretty-floatfmt

Conversation

@DresdenGman

Copy link
Copy Markdown

Fixes #71.

With tablefmt="pretty", an explicitly given floatfmt (or intfmt) was silently ignored: for the same data, floatfmt=".2f" renders 1.23 / 7.80 in simple, grid, pipe and fancy_grid, but 1.23456 / 7.8 in pretty.

The cause is that the pretty branch unconditionally set disable_numparse = True, so numeric columns were typed as strings and never reached the float/int formatting path. Simply removing that override would change pretty's default output, because the default floatfmt="g" would then reformat values such as 451.0 into 451, which existing tests pin down.

This keeps the by-design behaviour when the default formats are in effect, and only parses numbers when the user actually passes a custom floatfmt or intfmt (including per-column lists). An explicit disable_numparse=True still takes precedence, and pretty's centered alignment is unchanged.

Tests: two new tests, test_pretty_floatfmt and test_pretty_intfmt, which fail against the unmodified code. Full suite: 351 passed, 17 skipped, against a baseline of 349 passed, 17 skipped — the difference is exactly the two new tests.

The pretty format unconditionally disabled number parsing, so an
explicitly given floatfmt or intfmt was silently ignored. Keep the
existing by-design behaviour (numbers rendered as-is) when the
default formats are in effect, but parse numbers when the user
passes a custom floatfmt or intfmt.

Fixes astanin#71
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.

floatfmt doesn't work when tablefmt="pretty"

1 participant