Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-12695

[Python] bool value of scalars depends on data type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 4.0.0
    • None
    • Python
    • None
    • Windows 10
      python 3.9.4

    Description

      `pyarrow.Scalar` and its subclasses do not implement `_bool_` method. The default implementation does not seem to do the right thing. For example:

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

      Please consider implementing `__bool__` method. It seems reasonable to delegate to the `__bool__` method of the wrapped object.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mosalx Sergey Mozharov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: