0x26res opened a new issue, #43358:
URL: https://github.com/apache/arrow/issues/43358

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   Say I have a struct with non-nullable fields, If I try to create an empty 
array of this struct, the array is not valid.
   
   ```
   import pyarrow as pa
   import pytest
   
   
   def test_bad_nulls():
       struct_type = pa.struct(
           [
               pa.field("field_1", pa.string(), nullable=False),
               pa.field("field_2", pa.int64(), nullable=False),
           ]
       )
   
       with pytest.raises(
           pa.ArrowInvalid,
           match=r"Can't view array of type "
           r"struct\<field_1\: string not null, field_2\: int64 not null\> as "
           r"struct\<field_1\: string not null, field_2\: int64 not null\>"
           r"\: nulls in input cannot be viewed as non\-nullable",
       ):
           pa.nulls(size=10, type=struct_type).cast(struct_type)
   
       actual_nulls = pa.StructArray.from_arrays(
           [pa.array([""] * 10), pa.array([0] * 10)],
           fields=struct_type,
           mask=pa.array([True] * 10),
       )
       actual_nulls.cast(struct_type)
       assert actual_nulls.null_count == 10
       assert actual_nulls.to_pylist() == [None] * 10
   ```
   
   I guess it's because `pyarrow.nulls` initialize the nested arrays to nulls, 
but they are not nullable so they should be initialized to default values.
   
   Alternatively, the cast / validate method should not check for the validity 
of the nested arrays, when the parent struct array isn't valid/is null for this 
element. Though I don't think this is a good idea, because if the nested arrays 
are reused outside of the struct, then they become invalid.
   
   ### Component(s)
   
   Python


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