rambleraptor commented on code in PR #3997:
URL: https://github.com/apache/iceberg-python/pull/3997#discussion_r4353468414


##########
pyiceberg/conversions.py:
##########
@@ -310,9 +310,11 @@ def _(primitive_type: DecimalType, value: Decimal) -> 
bytes:
         bytes: The byte representation of `value`.
     """
     _, digits, exponent = value.as_tuple()
-    exponent = abs(int(exponent))
-    if exponent != primitive_type.scale:
-        raise ValueError(f"Cannot serialize value, scale of value does not 
match type {primitive_type}: {exponent}")
+    # A Decimal carries the negated scale as its exponent, so a value with a 
negative
+    # scale (1E+2) must not be read as if it had the matching positive one
+    value_scale = -int(exponent)
+    if value_scale != primitive_type.scale:
+        raise ValueError(f"Cannot serialize value, scale of value does not 
match type {primitive_type}: {value_scale}")

Review Comment:
   nit: I don't love this error message (decimal scale isn't always a term that 
people are immediately familiar with), but I think it'll be fine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to