From c9f01ea6ac062cf40f365222f6f6a91ebb23912f Mon Sep 17 00:00:00 2001 From: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:29:25 +0530 Subject: [PATCH 1/2] Render decimal human strings in plain notation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to_human_string for decimals falls through to str(), which renders small magnitudes in scientific notation — a decimal partition value of 0.00000012 shows up as 1.2E-7 in the partitions inspect table's lower and upper bound columns, while #4420 established plain notation for decimal JSON values. Register a Decimal override 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 four new parametrize cases fail on main and pass with the override; the 17 pyarrow-parametrized failures in this file are the pristine-main environment baseline, unchanged. Refs #4420. Signed-off-by: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com> --- pyiceberg/transforms.py | 9 +++++++++ tests/test_transforms.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/pyiceberg/transforms.py b/pyiceberg/transforms.py index 45c8ffd196..77d31ea13f 100644 --- a/pyiceberg/transforms.py +++ b/pyiceberg/transforms.py @@ -20,6 +20,7 @@ import struct from abc import ABC, abstractmethod from collections.abc import Callable +from decimal import Decimal from enum import IntEnum from functools import singledispatch from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar @@ -914,6 +915,14 @@ def _human_string(value: Any, _type: IcebergType) -> str: return str(value) +@_human_string.register(Decimal) +def _(value: Decimal, _type: IcebergType) -> str: + if isinstance(value.as_tuple().exponent, int) and value.as_tuple().exponent <= 0: + # str() switches to scientific notation for small magnitudes, such as 0E-8 + return f"{value:f}" + return str(value) + + @_human_string.register(bytes) def _(value: bytes, _type: IcebergType) -> str: return _base64encode(value) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 6ab7b52c4c..3674c1b9c0 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -420,6 +420,10 @@ def test_satisfies_order_of_method(transform: TimeTransform[Any], other_transfor (LongType(), -1234567890000, "-1234567890000"), (StringType(), "a/b/c=d", "a/b/c=d"), (DecimalType(9, 2), Decimal("-1.50"), "-1.50"), + (DecimalType(20, 8), Decimal("0.00000012"), "0.00000012"), + (DecimalType(20, 8), Decimal("0.00000000"), "0.00000000"), + (DecimalType(20, 8), Decimal("-0.00000012"), "-0.00000012"), + (DecimalType(38, 18), Decimal("0.000000000000000001"), "0.000000000000000001"), (FixedType(100), b"foo", "Zm9v"), ], ) From 561e3c0249939dbe8aea46a10a3b1d88c46d8263 Mon Sep 17 00:00:00 2001 From: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com> Date: Fri, 20 Nov 2026 20:43:16 +0530 Subject: [PATCH 2/2] Narrow the Decimal exponent type check in the human-string override Decimal.as_tuple's exponent element is the string 'n'/'N'/'F' for NaN and Infinity specials, so mypy rejects comparing it against int directly. Restore the isinstance narrowing the conversions.py counterpart uses (the one-line compression dropped it). Signed-off-by: Ayush Kumar Saha <225407166+AP24110011695@users.noreply.github.com> --- pyiceberg/transforms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyiceberg/transforms.py b/pyiceberg/transforms.py index 77d31ea13f..48df94b8ce 100644 --- a/pyiceberg/transforms.py +++ b/pyiceberg/transforms.py @@ -917,7 +917,9 @@ def _human_string(value: Any, _type: IcebergType) -> str: @_human_string.register(Decimal) def _(value: Decimal, _type: IcebergType) -> str: - if isinstance(value.as_tuple().exponent, int) and value.as_tuple().exponent <= 0: + # as_tuple's exponent is the string 'n'/'N'/'F' for NaN and Infinity specials + exponent = value.as_tuple().exponent + if isinstance(exponent, int) and exponent <= 0: # str() switches to scientific notation for small magnitudes, such as 0E-8 return f"{value:f}" return str(value)