Skip to content

[C++][Python] Casting extension types with list-based storage segfaults #37004

Description

@spenczar

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

I'm taking a table and casting it to its own schema. This should always work, but it errors in a certain case.

(this is deep in some library code - please forgive how strange this scenario is; just trust me that it really does happen!)

# An extension type which wraps list-of-int32:classMyExtensionType(pa.PyExtensionType):
def__init__(self):
pa.PyExtensionType.__init__(self, pa.list_(pa.int32()))
def__reduce__(self):
returnMyExtensionType, (),
# an array of this type:ext_array=pa.array([[1, 2, 3]], MyExtensionType())
# Wrap that in a struct:struct_array=pa.StructArray.from_arrays([ext_array], "x")
# Wrap the struct in a table:table=pa.Table.from_arrays([struct_array], ["field1"])

All of the above is fine, and then:

table.cast(table.schema)

Blows up:

File ~/.pyenv/versions/3.10.10/envs/general-3.10/lib/python3.10/site-packages/pyarrow/table.pxi:3616, in pyarrow.lib.Table.cast()
File ~/.pyenv/versions/3.10.10/envs/general-3.10/lib/python3.10/site-packages/pyarrow/table.pxi:3798, in pyarrow.lib.Table.from_arrays()
File ~/.pyenv/versions/3.10.10/envs/general-3.10/lib/python3.10/site-packages/pyarrow/table.pxi:2962, in pyarrow.lib.Table.validate()
File ~/.pyenv/versions/3.10.10/envs/general-3.10/lib/python3.10/site-packages/pyarrow/error.pxi:100, in pyarrow.lib.check_status()
ArrowInvalid: Column 0: In chunk 0: Invalid: Struct child array #0 invalid: Invalid: Expected 1 child arrays in array of type list<item: int32>, got 0

I can print table just fine:

pyarrow.Table
field1: struct<x: extension<arrow.py_extension_type<MyExtensionType>>>
child 0, x: extension<arrow.py_extension_type<MyExtensionType>>
----
field1: [
-- is_valid: all not null
-- child 0 type: extension<arrow.py_extension_type<MyExtensionType>>
[[1,2,3]]]

This is pyarrow version 12.0.1.

Component(s)

Python

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions