Repository navigation
Conversation
Preserve numeric values when the Decimal exponent differs from the schema scale for bytes and fixed encodings. Generated-by: OpenAI Codex
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.
What is the purpose of the change
Fixes AVRO-3834, reported by Steve Stagg.
The Python decimal encoder uses the value's digits without adjusting for the schema's scale. For example,
Decimal("3.1")withscale: 2is written as unscaled31and reads back as0.31. Bothbytesandfixeddecimals are affected.This change adjusts the unscaled integer by
10 ** (scale + exponent)before encoding it. Integer arithmetic keeps the result independent of the caller's Decimal precision. Values with too many fractional digits are still rejected as before.This is limited to scale adjustment. It does not add writer-side precision validation or address the separate existing negative-zero encoding issue.
Verifying this change
This change added tests and can be verified as follows:
DatumWriter/DatumReaderround trip, across bytes/fixed, positive/negative values, whole numbers, scientific notation, and scales 0, 2 and 4. The encoder runs under a low-precision Decimal context. These regressions fail on the original encoder.ruff format --check,ruff check, andmypy avro/passed.Documentation
AI disclosure: implementation and tests were prepared with OpenAI Codex; Claude Opus 5.5 reviewed the patch and drafted this description, which Codex edited. Review so far is by AI agents, not a human reviewer.