pyarrow.list_#

pyarrow.list_(value_type, int list_size=-1)#

Create ListType instance from child data type or field.

Parameters:
value_typeDataType or Field
list_sizeint, optional, default -1

If length == -1 then return a variable length list type. If length is greater than or equal to 0 then return a fixed size list type.

Returns:
list_typeDataType

Examples

Create an instance of ListType:

>>> import pyarrow as pa
>>> pa.list_(pa.string())
ListType(list<item: string>)
>>> pa.list_(pa.int32(), 2)
FixedSizeListType(fixed_size_list<item: int32>[2])

Use the ListType to create a scalar:

>>> pa.scalar(['foo', None], type=pa.list_(pa.string(), 2))
<pyarrow.FixedSizeListScalar: ['foo', None]>

or an array:

>>> pa.array([[1, 2], [3, 4]], pa.list_(pa.int32(), 2))
<pyarrow.lib.FixedSizeListArray object at ...>
[
  [
    1,
    2
  ],
  [
    3,
    4
  ]
]