Repository navigation
Render decimal human strings in plain notation - #4430
AP24110011695 wants to merge 2 commits into
Conversation
to_human_string for decimals falls through to str(), which renders small magnitudes in scientific notation — a decimal partition value of 0.00000012 shows up as 1.2E-7 in the partitions inspect table's lower and upper bound columns, while apache#4420 established plain notation for decimal JSON values. Register a Decimal override on the human-string helper using the same rule as the JSON path (plain f-notation when the exponent is zero or negative, str otherwise, which keeps the negative-scale scientific convention). The four new parametrize cases fail on main and pass with the override; the 17 pyarrow-parametrized failures in this file are the pristine-main environment baseline, unchanged. Refs apache#4420. Signed-off-by: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com>
Decimal.as_tuple's exponent element is the string 'n'/'N'/'F' for NaN and Infinity specials, so mypy rejects comparing it against int directly. Restore the isinstance narrowing the conversions.py counterpart uses (the one-line compression dropped it). Signed-off-by: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com>
rahulsmahadev
left a comment
There was a problem hiding this comment.
Thanks @AP24110011695! The four new cases fail on main and pass here, and the plain notation in the manifest bounds looks right.
I'd recommend keeping partition_to_path as it is. It uses the same to_human_string, so 0.00000012 would now be written to x=0.00000012/ instead of x=1.2E-7/. Java writes x=1.2E-7/ (BigDecimal.toString()), so Python would stop matching Java, and one partition could end up with files under both names.
The same symptom remains for truncate. With truncate[10] on decimal(20, 8), this PR still writes x_trunc=1.0E-7/ and shows -2.0E-7 as the manifest lower bound, the same as on main. One option that covers both: keep to_human_string unchanged and do the plain formatting in _partition_summaries_to_rows (inspect.py) for every transform.
Also, the bounds are in inspect.manifests(), not the partitions table, and the template's "Are there any user-facing changes?" section is missing.
What's changed
to_human_stringfor decimals falls through to plainstr(), which renders small magnitudes in scientific notation — a decimal partition value of0.00000012surfaces as1.2E-7in the partitions inspect table's lower/upper bound columns (_partition_summaries_to_rowsrenders bounds viafield.transform.to_human_string), while #4420 established plain notation for decimal JSON values with the exact samestr()hazard.This registers a
Decimaloverride on the human-string helper using the same rule as the JSON path: plain f-notation when the exponent is zero or negative,str()otherwise (which keeps the negative-scale scientific convention the conversions docstring documents). The human-string helper is what the identity transform and the inspect path route through.Test
Four new parametrize cases in
test_identity_human_string(small magnitude, zero, negative small magnitude, and a 38,18 case) — verified failing-first on main (1.2E-7/0E-8renderings) and passing with the override. The 17 pyarrow-parametrized failures in this file are the pristine-main environment baseline on this machine (verified by stash A/B: identical set, unchanged by this PR).AI disclosure: drafted with AI assistance, verified locally by running the failing-first cycle and an end-to-end write +
inspect.partitions()probe.