Repository navigation
Render decimal human strings in plain notation - #4430
AP24110011695 wants to merge 1 commit into
Conversation
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.
Per review: to_human_string must stay unchanged (partition_to_path uses it, and Java writes x=1.2E-7/ via BigDecimal.toString() — the override would split partitions across both names). The plain formatting now lives in _partition_summaries_to_rows (inspect.py) for every transform, covering manifests() bounds and the truncate case. Also adds the missing user-facing-changes section to the description. Signed-off-by: Ayush Kumar Saha <[email protected]>
561e3c0 to
95339d5
Compare
|
Reworked per your prescription (95339d5) — thanks for the partition_to_path catch, that would have split partitions across both names:
|
rahulsmahadev
left a comment
There was a problem hiding this comment.
Thanks @AP24110011695! On 95339d5 new data files go to x=1.2E-7/ again, as on main and in Java, truncate bounds render plain too, and the new test fails on main and passes here.
One thing I missed last time: Java's ManifestsTable.partitionSummariesToRows also goes through toHumanString, which falls back to BigDecimal.toString(), so Java's manifests table shows 1.2E-7 and 0E-8 for these bounds. I'd recommend noting in the description that this display now differs from Java, so maintainers can weigh it.
The "What's changed" and "Test" sections still describe the earlier to_human_string override, the partitions table and the test_identity_human_string cases. It may help to update them to the inspect.py helper and the new test, and to mention all_manifests(), which changes the same way.
| # Plain notation per the decimal JSON convention (#4420): str() would render | ||
| # the small magnitude as 1.2E-7 | ||
| assert summaries[0]["lower_bound"] == "0.00000012" | ||
| assert summaries[0]["upper_bound"] == "100.00000000" |
There was a problem hiding this comment.
Minor: 100.00000000 renders the same with str(), so this test still passes if the upper bound keeps to_human_string, and nothing covers truncate. Small bounds such as -0.00000012 and 0.00000012 on an identity and a truncate[10] column would pin both.
|
I'm in favor of leaving this as-is. Otherwise, PyIceberg would diverge from Java. |
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.Are there any user-facing changes?
Yes: decimal lower/upper bounds in the
manifests()inspect output now render in plain notation (0.00000012instead of1.2E-7), matching the decimal JSON convention from #4420. No API changes.