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

fix: don't raise NotImplementedError when reading empty array from Parquet #2194

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/awkward/_connect/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,11 @@ def handle_arrow(obj, generate_bitmasks=False, pass_empty_field=False):
elif isinstance(obj, pyarrow.lib.Table):
batches = obj.combine_chunks().to_batches()
if len(batches) == 0:
# FIXME: create a zero-length array with the right type
raise ak._errors.wrap_error(NotImplementedError)
# create an empty array following the input schema
return form_handle_arrow(
obj.schema,
pass_empty_field=pass_empty_field,
).length_zero_array(highlevel=False)
elif len(batches) == 1:
return handle_arrow(batches[0], generate_bitmasks, pass_empty_field)
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_1125_to_arrow_from_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,11 @@ def test_unionarray(tmp_path, extensionarray):
)
paarray = akarray.to_arrow(extensionarray=extensionarray)
arrow_round_trip(akarray, paarray, extensionarray)


@pytest.mark.parametrize("extensionarray", [False, True])
def test_empty_arrow(tmp_path, extensionarray):
akarray = ak.Array([{"x": 1, "y": 2.2}])[0:0]
paarray = ak.to_arrow_table(akarray, extensionarray=extensionarray)
arrow_round_trip(akarray, paarray, extensionarray)
parquet_round_trip(akarray, paarray, extensionarray, tmp_path)