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
11 changes: 11 additions & 0 deletions pyiceberg/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -914,6 +915,16 @@ def _human_string(value: Any, _type: IcebergType) -> str:
return str(value)


@_human_string.register(Decimal)
def _(value: Decimal, _type: IcebergType) -> str:
# 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)


@_human_string.register(bytes)
def _(value: bytes, _type: IcebergType) -> str:
return _base64encode(value)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
Expand Down
Loading