jorisvandenbossche commented on code in PR #39813:
URL: https://github.com/apache/arrow/pull/39813#discussion_r1481539129


##########
python/pyarrow/array.pxi:
##########
@@ -2570,23 +2588,18 @@ cdef class ListViewArray(Array):
         The values include null elements from sub-lists:
 
         >>> import pyarrow as pa
-        >>> values = [[1, 2], [3, 4, None, 6]]
-        >>> offsets = [0, None, 2]
+        >>> values = [1, 2, None, 3, 4]
+        >>> offsets = [0, 0, 1]
         >>> sizes = [2, 0, 4]
         >>> array = pa.ListViewArray.from_arrays(offsets, sizes, values)
         >>> array.values

Review Comment:
   Maybe also show `array` itself first (so you can compare with that output)?



##########
python/pyarrow/array.pxi:
##########
@@ -2557,9 +2572,12 @@ cdef class ListViewArray(Array):
         Return the underlying array of values which backs the ListViewArray
         ignoring the array's offset and sizes.
 
-        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.
+        The values array may be out of order and/or contain additional values
+        that are not found in the logical representation of the array. The only
+        guarantee is that each non-null value in the ListView Array is 
contiguous.
+
+        Compare with :meth:`flatten`, which returns only the non-null
+        values taking into consideration the array's offset.

Review Comment:
   ```suggestion
           values taking into consideration the array's order and offset.
   ```



##########
python/pyarrow/array.pxi:
##########
@@ -2842,20 +2910,65 @@ cdef class LargeListViewArray(Array):
         --------
 
         >>> import pyarrow as pa
-        >>> values = [[1, 2], [3, 4, None, 6]]
-        >>> offsets = [0, None, 2]
+        >>> values = [1, 2, None, 3, 4]
+        >>> offsets = [0, 0, 1]
         >>> sizes = [2, 0, 4]
         >>> array = pa.LargeListViewArray.from_arrays(offsets, sizes, values)
-        >>> array.offsets
+        >>> array.sizes
         <pyarrow.lib.Int64Array object at ...>
         [
+          2,
           0,
-          0,
-          2
+          4
         ]
         """
         return pyarrow_wrap_array((<CLargeListViewArray*> self.ap).sizes())
 
+    def flatten(self, pool=None):

Review Comment:
   ```suggestion
       def flatten(self, memory_pool=None):
   ```



##########
python/pyarrow/array.pxi:
##########
@@ -2638,20 +2651,66 @@ cdef class ListViewArray(Array):
         Examples
         --------
         >>> import pyarrow as pa
-        >>> values = [[1, 2], [3, 4, None, 6]]
-        >>> offsets = [0, None, 2]
+        >>> values = [1, 2, None, 3, 4]
+        >>> offsets = [0, 0, 1]
         >>> sizes = [2, 0, 4]
         >>> array = pa.ListViewArray.from_arrays(offsets, sizes, values)
-        >>> array.offsets
+        >>> array.sizes
         <pyarrow.lib.Int32Array object at ...>
         [
+          2,
           0,
-          0,
-          2
+          4
         ]
         """
         return pyarrow_wrap_array((<CListViewArray*> self.ap).sizes())
 
+    def flatten(self, pool=None):

Review Comment:
   ```suggestion
       def flatten(self, memory_pool=None):
   ```
   
   We are not very consistent about it, but at least in this file we use 
`memory_pool` more than `pool` .. (something to clean up at some point)



##########
python/pyarrow/array.pxi:
##########
@@ -2638,20 +2651,66 @@ cdef class ListViewArray(Array):
         Examples
         --------
         >>> import pyarrow as pa
-        >>> values = [[1, 2], [3, 4, None, 6]]
-        >>> offsets = [0, None, 2]
+        >>> values = [1, 2, None, 3, 4]
+        >>> offsets = [0, 0, 1]
         >>> sizes = [2, 0, 4]
         >>> array = pa.ListViewArray.from_arrays(offsets, sizes, values)
-        >>> array.offsets
+        >>> array.sizes
         <pyarrow.lib.Int32Array object at ...>
         [
+          2,
           0,
-          0,
-          2
+          4
         ]
         """
         return pyarrow_wrap_array((<CListViewArray*> self.ap).sizes())
 
+    def flatten(self, pool=None):
+        """
+        Unnest this ListViewArray by one level.
+
+        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
+        it takes care of the slicing offset as well as null elements backed
+        by non-empty sub-lists.
+
+        Parameters
+        ----------
+        pool : MemoryPool, optional
+
+        Returns
+        -------
+        result : Array
+
+        Examples
+        --------
+
+        >>> import pyarrow as pa
+        >>> values = [1, 2, 3, 4]
+        >>> offsets = [2, 1, 0]
+        >>> sizes = [2, 2, 2]
+        >>> array = pa.ListViewArray.from_arrays(offsets, sizes, values)
+        >>> array.flatten()

Review Comment:
   Maybe here show both `array` and `array.values` outputs as well so it's 
easier to compare the different ones?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to