pitrou commented on code in PR #45818:
URL: https://github.com/apache/arrow/pull/45818#discussion_r2106939044


##########
python/pyarrow/scalar.pxi:
##########
@@ -219,6 +220,8 @@ cdef class BooleanScalar(Scalar):
         cdef CBooleanScalar* sp = <CBooleanScalar*> self.wrapped.get()
         return sp.value if sp.is_valid else None
 
+    def __bool__(self):
+        return self.as_py()

Review Comment:
   I missed this, but we should be careful if the scalar is not valid, as 
`None` isn't a valid return value for `__bool__`:
   ```python
   >>> class B:
   ...:     def __bool__(self): return None
   ...: 
   >>> bool(B())
     ...
   TypeError: __bool__ should return bool, returned NoneType
   
   ```
   
   We could probably circumvent this by writing:
   ```python
       def __bool__(self):
           return self.as_py() or False
   ```
   



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