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

when writing in batches, handle all na arrays properly #306

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions python/lance/data/convert/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,20 @@ def _convert_field(self, name, typ, col):
"""pyarrow is unable to convert ExtensionTypes properly in pa.Table.from_pandas"""
if isinstance(typ, pa.ExtensionType):
storage = pa.array(col, type=typ.storage_type)
arr = pa.ExtensionArray.from_storage(typ, storage)
return pa.ExtensionArray.from_storage(typ, storage)
elif pa.types.is_list(typ):
native_arr = pa.array(col)
if isinstance(native_arr, pa.NullArray):
return pa.nulls(len(native_arr), typ)
offsets = native_arr.offsets
values = native_arr.values.to_numpy(zero_copy_only=False)
return pa.ListArray.from_arrays(
offsets, self._convert_field(f"{name}.elements", typ.value_type, values)
)
elif pa.types.is_struct(typ):
native_arr = pa.array(col)
if isinstance(native_arr, pa.NullArray):
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this was a fix for the demo notebook?

Could you add a test please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

return pa.nulls(len(native_arr), typ)
arrays = []
for subfield in typ:
sub_arr = native_arr.field(subfield.name)
Expand All @@ -127,8 +131,7 @@ def _convert_field(self, name, typ, col):
arrays.append(converted)
return pa.StructArray.from_arrays(arrays, fields=typ)
else:
arr = pa.array(col, type=typ)
return arr
return pa.array(col, type=typ)

def make_embedded_dataset(
self,
Expand Down