From fcead19a659bd05f3edbf8b5ad74722bdf702ef7 Mon Sep 17 00:00:00 2001 From: "Sung Yun (CODE SIGNING KEY)" Date: Fri, 19 Jun 2026 14:53:11 -0400 Subject: [PATCH] allow optional whitespace around parameters similar to other language implementations --- pyiceberg/types.py | 2 +- tests/test_types.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pyiceberg/types.py b/pyiceberg/types.py index 3c98215366..f530450aad 100644 --- a/pyiceberg/types.py +++ b/pyiceberg/types.py @@ -57,7 +57,7 @@ from pyiceberg.utils.parsing import ParseNumberFromBrackets from pyiceberg.utils.singleton import Singleton -DECIMAL_REGEX = re.compile(r"decimal\((\d+),\s*(\d+)\)") +DECIMAL_REGEX = re.compile(r"decimal\(\s*(\d+)\s*,\s*(\d+)\s*\)") FIXED = "fixed" FIXED_PARSER = ParseNumberFromBrackets(FIXED) diff --git a/tests/test_types.py b/tests/test_types.py index 5e95687ba2..27f4cacc85 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -514,6 +514,21 @@ def test_deserialization_decimal() -> None: assert decimal.scale == 25 +@pytest.mark.parametrize( + "decimal_str", + [ + "decimal(9,2)", + "decimal(9, 2)", + "decimal( 9, 2 )", + "decimal( 9 , 2 )", + "decimal(9 ,2)", + ], +) +def test_deserialization_decimal_optional_whitespace(decimal_str: str) -> None: + # Readers accept optional whitespace around parameters and the separator. + assert DecimalType.model_validate_json(f'"{decimal_str}"') == DecimalType(9, 2) + + def test_deserialization_decimal_failure() -> None: with pytest.raises(ValidationError) as exc_info: _ = DecimalType.model_validate_json('"decimal(abc, def)"')