Skip to content

Commit fcead19

Browse files
committed
allow optional whitespace around parameters similar to other language implementations
1 parent 6da06ad commit fcead19

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

pyiceberg/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
from pyiceberg.utils.parsing import ParseNumberFromBrackets
5858
from pyiceberg.utils.singleton import Singleton
5959

60-
DECIMAL_REGEX = re.compile(r"decimal\((\d+),\s*(\d+)\)")
60+
DECIMAL_REGEX = re.compile(r"decimal\(\s*(\d+)\s*,\s*(\d+)\s*\)")
6161
FIXED = "fixed"
6262
FIXED_PARSER = ParseNumberFromBrackets(FIXED)
6363

tests/test_types.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,21 @@ def test_deserialization_decimal() -> None:
514514
assert decimal.scale == 25
515515

516516

517+
@pytest.mark.parametrize(
518+
"decimal_str",
519+
[
520+
"decimal(9,2)",
521+
"decimal(9, 2)",
522+
"decimal( 9, 2 )",
523+
"decimal( 9 , 2 )",
524+
"decimal(9 ,2)",
525+
],
526+
)
527+
def test_deserialization_decimal_optional_whitespace(decimal_str: str) -> None:
528+
# Readers accept optional whitespace around parameters and the separator.
529+
assert DecimalType.model_validate_json(f'"{decimal_str}"') == DecimalType(9, 2)
530+
531+
517532
def test_deserialization_decimal_failure() -> None:
518533
with pytest.raises(ValidationError) as exc_info:
519534
_ = DecimalType.model_validate_json('"decimal(abc, def)"')

0 commit comments

Comments
 (0)