Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyiceberg/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,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)


Expand Down
3 changes: 3 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,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"),
Expand Down
Loading