Skip to content

Commit

Permalink
apacheGH-35740: Add documentation for list arrays' values property (a…
Browse files Browse the repository at this point in the history
…pache#35865)

Just docs.

I'm a little shaky on my understanding of exactly what's going on with FixedSizeListArray.values, and its behavior with nulls, so that wording might deserve a careful read.
* Closes: apache#35740

Lead-authored-by: Spencer Nelson <[email protected]>
Co-authored-by: Joris Van den Bossche <[email protected]>
Co-authored-by: Alenka Frim <[email protected]>
Signed-off-by: AlenkaF <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2023
1 parent b6ab909 commit 6837d05
Showing 1 changed file with 171 additions and 1 deletion.
172 changes: 171 additions & 1 deletion python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,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 @@ -2103,6 +2103,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 @@ -2190,6 +2256,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 @@ -2346,6 +2480,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

0 comments on commit 6837d05

Please sign in to comment.