randolf-scholz commented on issue #34987:
URL: https://github.com/apache/arrow/issues/34987#issuecomment-3552310153

   @AlenkaF Thanks for the heads-up!
   
   > This issue slipped past and so the current code decides boolean value of 
None is False and it only implements the method for BooleanScalar, not other 
scalars.
   
   Well, as I explained in 
https://github.com/apache/arrow/pull/34993#issuecomment-1685415286 this could 
have some unexpected consequences, and it may be safer to actually error on 
casting `null` to `bool`. For example:
   
   ```python
   import pyarrow as pa
   measured_value = pa.scalar(None, type=pa.float64())  # missing value
   limit_value = pa.scalar(1.0, type=pa.float64())
   exceeds_limit = pa.compute.greater(measured_value, limit_value)
   
   # user forgot to handle the missing value case
   if exceeds_limit:  
       raise ValueError("Measured value exceeds safe limit")
   else:  # <- we incorrect assume safe branch when sensor is malfunctioning.
        # continue system oepration
        pass
   ```
   
   While it is true that python treats `None` as `False` in a boolean context, 
python forbids arithmetic with `None`, e.g. `None > 1.0` raises a type error 
rather than returning `None`.
   
   
   
   
   


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

Reply via email to