milesgranger commented on code in PR #13894:
URL: https://github.com/apache/arrow/pull/13894#discussion_r958434899


##########
python/pyarrow/tests/test_array.py:
##########
@@ -919,6 +919,53 @@ def test_list_from_arrays(list_array_type, 
list_type_factory):
         list_array_type.from_arrays(offsets, values, type=typ)
 
 
[email protected](('list_array_type', 'list_type_factory'), (
+    (pa.ListArray, pa.list_),
+    (pa.LargeListArray, pa.large_list)
+))
[email protected]("arr", (
+    [None, [0]],
+    [None, [0, None], [0]],
+    [[0], [1]],
+))
+def test_list_array_types_from_arrays(
+    list_array_type, list_type_factory, arr
+):
+    arr = pa.array(arr, list_type_factory(pa.int8()))
+    reconstructed_arr = list_array_type.from_arrays(
+        arr.offsets, arr.values, mask=arr.is_null())
+    assert arr == reconstructed_arr

Review Comment:
   Can fix this by padding the front of `mask` by offset length:
   ```python
   >>> arr = pa.array([[0], None, [0, None], [0]], pa.list_(pa.int8()))
   >>> arr_ = arr[1:]
   >>> arr_.is_null()
   <pyarrow.lib.BooleanArray object at 0x7fcf3dce8f40>
   [
     true,
     false,
     false
   ]
   
   >>> arr_
   <pyarrow.lib.ListArray object at 0x7fcf3dce3a00>
   [
     null,
     [
       0,
       null
     ],
     [
       0
     ]
   ]
   
   # Prepending with any value seems to work True or False, just needs to align 
with the offset
   >>> pa.ListArray.from_arrays(arr_.offsets, arr_.values, mask=pa.array([True, 
True, False, False]))
   <pyarrow.lib.ListArray object at 0x7fcf3e9595e0>
   [
     null,
     [
       0,
       null
     ],
     [
       0
     ]
   ]
   
   ```
   
   Initially planning to modify the `null_bitmap` on the C++ side in such a 
scenario; where it's length doesn't match the length of values, but curious if 
it's 'safe' to modify that `Buffer`'s data, or if a small preprocessing of the 
mask at Cython level is "more better".



-- 
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