Skip to content

[Python][C++] Casting a list of struct array with null field results in invalid result #43838

Open

Description

@Angel-212

Describe the bug, including details regarding any error messages, version, and platform.

OS: MacOS Sonoma 14.6.1
Python: 3.10.14
pyarrow: 17.0.0

Snippet to reproduce:

import pyarrow as pa

fields = [('b', pa.null()),('g', pa.string())]
dtype = pa.list_(pa.struct(fields))
arr  = pa.array([[{'b': None, 'g': None}, {'b': None, 'g': 'moo'}]], type=dtype)
carr = pa.chunked_array(arr)
ext_arr = carr.cast(dtype, safe=True)
print(ext_arr) # prints Invalid array but no exception
print(len(ext_arr)) # Len is 1
print(ext_arr[0]) # Raises ArrowIndexError

Component(s)

Python

Activity

  1. changed the title [-]ChunkedArray cast to data type containing null results in ArrowIndexError when accessed[/-] [+][Python][C++] Casting a list of struct array with null field results in invalid result[/+] on Aug 27, 2024
  2. jorisvandenbossche commented on Aug 27, 2024

    @jorisvandenbossche
    Member

    @Angel-212 thanks for the report!

    The issue already happens with the plain (non-chunked) array as well. And the repr also shows it being invalid (which is then the reason that a getitem operation errors):

    In [24]: arr.cast(dtype)
    Out[24]: 
    <pyarrow.lib.ListArray object at 0x7f0536bbd480>
    <Invalid array: List child array invalid: Invalid: Struct child array #0 has length smaller than expected for struct array (1 < 2)>
    
  3. added 2 commits that reference this issue on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions