Repository navigation
Write decimal default values in plain notation - #4420
Open
gedaliakliger wants to merge 1 commit into
Open
gedaliakliger wants to merge 1 commit into
gedaliakliger wants to merge 1 commit into
Conversation
str() renders a Decimal with a small magnitude in scientific notation, so a decimal(20, 8) default of zero was written to table metadata as 0E-8. The spec uses the digits after the decimal point to carry the scale, and Java writes toPlainString() for a non-negative scale.
This branch has not been deployed
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.
Rationale for this change
to_jsonfor aDecimalTypereturnsstr(val), and Python renders a smallDecimalin scientific notation. Adecimal(20, 8)column with a default of zero gets"initial-default": "0E-8"in the table metadata, and0.00000010becomes1.0E-7.The spec's JSON single-value serialization uses the number of digits to the right of the decimal point to indicate a positive scale, and keeps scientific notation for negative scales. Java's
SingleValueParser.toJsondoes the same:toPlainString()whenscale() >= 0, otherwisetoString().This writes the plain form when the exponent is zero or negative and leaves the other cases as they are.
Are these changes tested?
Three new cases in
test_json_single_serialization(tests/test_conversions.py). They fail onmain(0E-8,-1.2E-7,1E-18) and pass with this change.Ran locally:
pytest tests/test_conversions.py tests/test_types.py -m unit, andprek run ruff ruff-format mypyon the two changed files. The full unit and integration suites are left to CI.Are there any user-facing changes?
Decimal
initial-defaultandwrite-defaultvalues with a small magnitude are written in plain notation. Metadata that already holds the scientific form still reads.