This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new f26689aaa Write decimal default values in plain notation (#4420)
f26689aaa is described below
commit f26689aaa29135a31fc14474dd363c7600d1e173
Author: Gedalia Kliger <[email protected]>
AuthorDate: Wed Nov 18 21:29:44 2026 +0000
Write decimal default values in plain notation (#4420)
Write decimal JSON single values in plain notation
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.
---
pyiceberg/conversions.py | 4 ++++
tests/test_conversions.py | 3 +++
2 files changed, 7 insertions(+)
diff --git a/pyiceberg/conversions.py b/pyiceberg/conversions.py
index 3997b83dc..eee8da504 100644
--- a/pyiceberg/conversions.py
+++ b/pyiceberg/conversions.py
@@ -524,6 +524,10 @@ def _(_: DecimalType, val: Decimal) -> str:
decimal point is used to indicate scale, for values with a negative scale,
the scientific notation is used and the exponent must equal the negated
scale.
"""
+ exponent = val.as_tuple().exponent
+ if isinstance(exponent, int) and exponent <= 0:
+ # str() switches to scientific notation for small values, such as 0E-8
+ return f"{val:f}"
return str(val)
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index e1d1940ea..fbab096fa 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -603,6 +603,9 @@ def test_datetime_obj_to_bytes(primitive_type:
PrimitiveType, value: datetime |
(DecimalType(9, 4), Decimal("123.4500"), "123.4500"),
(DecimalType(9, 0), Decimal("2"), "2"),
(DecimalType(9, 9), Decimal("0.123456789"), "0.123456789"),
+ (DecimalType(20, 8), Decimal("0.00000000"), "0.00000000"),
+ (DecimalType(20, 8), Decimal("-0.00000012"), "-0.00000012"),
+ (DecimalType(38, 18), Decimal("0.000000000000000001"),
"0.000000000000000001"),
(DateType(), date(2017, 11, 16), "2017-11-16"),
(TimeType(), time(22, 31, 8, 123456), "22:31:08.123456"),
(TimestampType(), datetime(2017, 11, 16, 22, 31, 8, 123456),
"2017-11-16T22:31:08.123456"),