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

[Python] Scalar constructors should be callable

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Python
    • None

    Description

      Currently, to create a Scalar instance you must call the pa.scalar factory function. This works fine for the simplest types, but not for more elaborate ones.

      For example, in C++ it is trivial to create a ListScalar from the embedded std::shared_ptr<Array>. But not in Python:

      >>> arr = pa.array(["abc", "def", "ghi"])
      >>> pa.ListScalar(arr)
      Traceback (most recent call last):
        Input In [7] in <cell line: 1>
          pa.ListScalar(arr)
      TypeError: __init__() takes exactly 0 positional arguments (1 given)
      

      There is a clumsy workaround that creates an intermediate ListArray with trivial offsets:

      >>> list_arr = pa.ListArray.from_arrays([0, len(arr)], arr)
      >>> list_arr[0]
      <pyarrow.ListScalar: ['abc', 'def', 'ghi']>
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              apitrou Antoine Pitrou
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: