Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Cannot cast nested nullable field to not-nullable #33592

Open
asfimport opened this issue Dec 8, 2022 · 4 comments
Open

[Python] Cannot cast nested nullable field to not-nullable #33592

asfimport opened this issue Dec 8, 2022 · 4 comments

Comments

@asfimport
Copy link
Collaborator

Casting from nullable field to not-nullable works provided all values are present. So for example this is a valid cast:

table = pa.table({'column_1': pa.array([1, 2 ,3])})table.cast(
    pa.schema([
        f.with_nullable(False) for f in table.schema
    ])
)

But it doesn't work for nested field. Here's an example:

import pyarrow as pa

record = {"nested_int": 1}

data_type = pa.struct(
    [
        pa.field("nested_int", pa.int32(), nullable=True),
    ]
)

data_type_after = pa.struct(
    [
        pa.field("nested_int", pa.int32(), nullable=False),
    ]
)

table = pa.table({"column_1": pa.array([record], data_type)})

table.cast(pa.schema([pa.field("column_1", data_type_after)])) 

Throws:

pyarrow.lib.ArrowTypeError: cannot cast nullable field to non-nullable field: struct<nested_int: int32> struct<nested_int: int32 not null> 

This is somewhat related to #13177 and https://issues.apache.org/jira/browse/ARROW-16603 

Reporter: &res / @0x26res

Note: This issue was originally created as ARROW-18430. Please see the migration documentation for further details.

@jorisvandenbossche
Copy link
Member

Just ran into this as well:

>>> arr = pa.array([{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 3.0}])
>>> arr.type
StructType(struct<x: double, y: double>)

>>> arr.cast(pa.struct([pa.field("x", pa.float64(), nullable=False), pa.field("y", pa.float64(), nullable=False)]))
...
ArrowTypeError: cannot cast nullable field to non-nullable field: struct<x: double, y: double> struct<x: double not null, y: double not null>
/home/joris/scipy/repos/arrow/cpp/src/arrow/compute/exec.cc:920  kernel_->exec(kernel_ctx_, input, &output)
/home/joris/scipy/repos/arrow/cpp/src/arrow/compute/function.cc:277  executor->Execute(input, &listener)

@raulcd
Copy link
Member

raulcd commented Apr 9, 2024

I am moving this to 17.0.0. Let me know if it should be part of 16.0.0

@wabu
Copy link

wabu commented Aug 6, 2024

Also ran into this, would be great to address this soonish.

@NickCrews
Copy link
Contributor

NickCrews commented Aug 21, 2024

Also just ran into this. Not familiar at all with arrows codebase, but if this isn't that hard and someone can give me pointers, I can take a stab at this. Opened #43782 as a first attempt, I would love some help with it if you can.

NickCrews added a commit to NickCrews/arrow that referenced this issue Aug 21, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Aug 21, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Aug 21, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Aug 22, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Sep 16, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Sep 18, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Sep 24, 2024
@raulcd raulcd modified the milestones: 18.0.0, 19.0.0 Oct 9, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Dec 13, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Dec 13, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Dec 13, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Dec 13, 2024
NickCrews added a commit to NickCrews/arrow that referenced this issue Dec 13, 2024
@jorisvandenbossche jorisvandenbossche modified the milestones: 19.0.0, 20.0.0 Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants