Ankitraj-builds opened a new pull request, #4442:
URL: https://github.com/apache/iceberg-python/pull/4442

   Closes #4441
   
   # Rationale for this change
   
   `FloatLiteral.to(DecimalType)` and `DoubleLiteral.to(DecimalType)` used 
`Decimal(self.value)`, which takes the exact binary value of the float. For 
values like 2.675 that value is 2.67499999..., so `ROUND_HALF_UP` rounded down: 
`literal(2.675).to(DecimalType(10, 2))` gave 2.67 instead of 2.68. This also 
changed the bound literal of filters on decimal columns, e.g. `EqualTo("price", 
2.675)` bound to 2.67.
   
   This now uses `Decimal(str(self.value))`, the shortest decimal that 
round-trips to the float. That matches Java, which uses 
`BigDecimal.valueOf(value).setScale(scale, RoundingMode.HALF_UP)`.
   
   ## Are these changes tested?
   
   Yes. `test_float_and_double_to_decimal_round_half_up_on_shortest_repr` in 
`tests/expressions/test_literals.py` covers 2.675, 1.005 and -2.675 (which 
round the wrong way on main), plus 0.125 and 2.674 as controls, for both 
`FloatLiteral` and `DoubleLiteral`. The three wrong cases fail on main and pass 
with this change. All tests in `tests/expressions` and 
`tests/test_conversions.py` pass.
   
   ## Are there any user-facing changes?
   
   Yes. Float and double values converted to a decimal type (for example in 
filters on decimal columns) now round like Java, Spark and Postgres: 2.675 
becomes 2.68.


-- 
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