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

PyArrow: Pass in null-mask #1264

Merged
merged 4 commits into from
Oct 29, 2024
Merged

PyArrow: Pass in null-mask #1264

merged 4 commits into from
Oct 29, 2024

Conversation

Fokko
Copy link
Contributor

@Fokko Fokko commented Oct 29, 2024

Fixes #1255

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

return pa.StructArray.from_arrays(
arrays=field_arrays,
fields=pa.struct(fields),
mask=struct_array.is_null() if isinstance(struct_array, pa.StructArray) else None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyarrow_table: pa.Table = pa.Table.from_pylist(records, schema=schema)
table.append(pyarrow_table)

assert pyarrow_table.to_pandas()["struct_field_1"].tolist() == table.scan().to_pandas()["struct_field_1"].tolist()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the null masking is also done by pandas.

>>> pyarrow_table['struct_field_1']
<pyarrow.lib.ChunkedArray object at 0x10482c6d0>
[
  -- is_valid:
      [
      false
    ]
  -- child 0 type: string
    [
      ""
    ]
  -- child 1 type: int32
    [
      0
    ]
  -- child 2 type: float
    [
      0
    ]
]
>>> pyarrow_table['struct_field_1'].to_pandas()
0    None
Name: struct_field_1, dtype: object

@Fokko Fokko merged commit 9a6a9a1 into apache:main Oct 29, 2024
7 checks passed
@Fokko Fokko deleted the fd-null branch October 29, 2024 21:19
@Fokko
Copy link
Contributor Author

Fokko commented Oct 29, 2024

Thanks for the prompt review @kevinjqliu

sungwy pushed a commit to sungwy/iceberg-python that referenced this pull request Dec 7, 2024
* PyArrow: Pass in null-mask

* Add missing flag
sungwy pushed a commit to sungwy/iceberg-python that referenced this pull request Dec 7, 2024
* PyArrow: Pass in null-mask

* Add missing flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why is the struct field not null when the data is empty?
2 participants