Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 171 additions & 1 deletion python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ cdef class BaseListArray(Array):
The returned Array is logically a concatenation of all the sub-lists
in this Array.

Note that this method is different from ``self.values()`` in that
Note that this method is different from ``self.values`` in that
it takes care of the slicing offset as well as null elements backed
by non-empty sub-lists.

Expand Down Expand Up @@ -2053,6 +2053,72 @@ cdef class ListArray(BaseListArray):

@property
def values(self):
"""
Return the underlying array of values which backs the ListArray
ignoring the array's offset.

If any of the list elements are null, but are backed by a
non-empty sub-list, those elements will be included in the
output.

Compare with :meth:`flatten`, which returns only the non-null
values taking into consideration the array's offset.

Returns
-------
values : Array

See Also
--------
ListArray.flatten : ...

Examples
--------

The values include null elements from sub-lists:

>>> import pyarrow as pa
>>> array = pa.array([[1, 2], None, [3, 4, None, 6]])
>>> array.values
<pyarrow.lib.Int64Array object at ...>
[
1,
2,
3,
4,
null,
6
]

If an array is sliced, the slice still uses the same
underlying data as the original array, just with an
offset. Since values ignores the offset, the values are the
same:

>>> sliced = array.slice(1, 2)
>>> sliced
<pyarrow.lib.ListArray object at ...>
[
null,
[
3,
4,
null,
6
]
]
>>> sliced.values
<pyarrow.lib.Int64Array object at ...>
[
1,
2,
3,
4,
null,
6
]

"""
cdef CListArray* arr = <CListArray*> self.ap
return pyarrow_wrap_array(arr.values())

Expand Down Expand Up @@ -2140,6 +2206,74 @@ cdef class LargeListArray(BaseListArray):

@property
def values(self):
"""
Return the underlying array of values which backs the LargeListArray
ignoring the array's offset.

If any of the list elements are null, but are backed by a
non-empty sub-list, those elements will be included in the
output.

Compare with :meth:`flatten`, which returns only the non-null
values taking into consideration the array's offset.

Returns
-------
values : Array

See Also
--------
LargeListArray.flatten : ...

Examples
--------

The values include null elements from the sub-lists:

>>> import pyarrow as pa
>>> array = pa.array(
... [[1, 2], None, [3, 4, None, 6]],
... type=pa.large_list(pa.int32()),
... )
>>> array.values
<pyarrow.lib.Int32Array object at ...>
[
1,
2,
3,
4,
null,
6
]

If an array is sliced, the slice still uses the same
underlying data as the original array, just with an
offset. Since values ignores the offset, the values are the
same:

>>> sliced = array.slice(1, 2)
>>> sliced
<pyarrow.lib.LargeListArray object at ...>
[
null,
[
3,
4,
null,
6
]
]
>>> sliced.values
<pyarrow.lib.Int32Array object at ...>
[
1,
2,
3,
4,
null,
6
]
"""
cdef CLargeListArray* arr = <CLargeListArray*> self.ap
return pyarrow_wrap_array(arr.values())

Expand Down Expand Up @@ -2296,6 +2430,42 @@ cdef class FixedSizeListArray(BaseListArray):

@property
def values(self):
"""
Return the underlying array of values which backs the
FixedSizeListArray.

Note even null elements are included.

Compare with :meth:`flatten`, which returns only the non-null
sub-list values.

Returns
-------
values : Array

See Also
--------
FixedSizeListArray.flatten : ...

Examples
--------
>>> import pyarrow as pa
>>> array = pa.array(
... [[1, 2], None, [3, None]],
... type=pa.list_(pa.int32(), 2)
... )
>>> array.values
<pyarrow.lib.Int32Array object at ...>
[
1,
2,
null,
null,
3,
null
]

"""
cdef CFixedSizeListArray* arr = <CFixedSizeListArray*> self.ap
return pyarrow_wrap_array(arr.values())

Expand Down