[
https://issues.apache.org/jira/browse/ARROW-12695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17347229#comment-17347229
]
Sergey Mozharov commented on ARROW-12695:
-----------------------------------------
[~jorisvandenbossche] The main concern is that bool value depends on the data
type. I can think of two options:
* delegate to {{__bool__}} method of the wrapped Python object. For invalid
scalars, that would be {{None}} so the bool value will be {{False}}
* make all scalars, valid or invalid, with all types return True, which I
think is the default for all python objects that do not define {{__len__}}
method
I am leaning towards the first option because it is easier to reason about and
would be simple to implement.
> [Python] bool value of scalars depends on data type
> ---------------------------------------------------
>
> Key: ARROW-12695
> URL: https://issues.apache.org/jira/browse/ARROW-12695
> Project: Apache Arrow
> Issue Type: Bug
> Components: Python
> Affects Versions: 4.0.0
> Environment: Windows 10
> python 3.9.4
> Reporter: Sergey Mozharov
> Priority: Major
>
> `pyarrow.Scalar` and its subclasses do not implement `__bool__` method. The
> default implementation does not seem to do the right thing. For example:
> {code:java}
> >>> import pyarrow as pa
> >>> na_value = pa.scalar(None, type=pa.int32())
> >>> bool(na_value)
> True
> >>> na_value = pa.scalar(None, type=pa.struct([('a', pa.int32())]))
> >>> bool(na_value)
> False
> >>> bool(pa.scalar(None, type=pa.list_(pa.int32())))
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "pyarrow\scalar.pxi", line 572, in pyarrow.lib.ListScalar.__len__
> TypeError: object of type 'NoneType' has no len()
> >>>
> {code}
> Please consider implementing `___bool____` method. It seems reasonable to
> delegate to the `____bool___` method of the wrapped object.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)