Skip to content

Commit

Permalink
sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Nov 20, 2024
1 parent 79d4053 commit c5a952d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
5 changes: 2 additions & 3 deletions python/src/nanoarrow/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ def get_pyiter(
) -> Optional[Iterator]:
return None

def get_sequence_converter(
self, params, c_array_view: CArrayView, offset: int, length: int
):
def get_sequence_converter(self, c_schema):
return None


global_extension_registry = {}


def resolve_extension(c_schema_view: CSchemaView) -> Optional[Extension]:
extension_name = c_schema_view.extension_name
if extension_name in global_extension_registry:
Expand Down
8 changes: 7 additions & 1 deletion python/src/nanoarrow/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from nanoarrow._array import CArrayView
from nanoarrow.c_array_stream import c_array_stream
from nanoarrow.c_schema import c_schema, c_schema_view
from nanoarrow.extension import resolve_extension
from nanoarrow.schema import Schema

from nanoarrow import _types
Expand Down Expand Up @@ -183,6 +184,8 @@ def get_iterator(cls, obj, schema=None):

def __init__(self, schema, *, array_view=None):
super().__init__(schema, array_view=array_view)
self._ext = resolve_extension(self._schema_view)
self._ext_params = self._ext.get_params(schema) if self._ext else None

self._children = list(
map(self._make_child, self._schema.children, self._array_view.children)
Expand All @@ -208,11 +211,14 @@ def __iter__(self):

def _iter_chunk(self, offset, length):
"""Iterate over all elements in a slice of the current chunk"""

# Check for an extension type first since this isn't reflected by
# self._schema_view.type_id. Currently we just return the storage
# iterator with a warning for extension types.
maybe_extension_name = self._schema_view.extension_name
if maybe_extension_name:
if self._ext:
return self._ext.get_pyiter(self._ext_params, self._array_view, offset, length)
elif maybe_extension_name:
self._warn(
f"Converting unregistered extension '{maybe_extension_name}' "
"as storage type",
Expand Down
1 change: 1 addition & 0 deletions python/src/nanoarrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ py_sources = [
'c_buffer.py',
'c_schema.py',
'device.py',
'extension.py',
'ipc.py',
'iterator.py',
'_repr_utils.py',
Expand Down
15 changes: 12 additions & 3 deletions python/src/nanoarrow/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from nanoarrow._buffer import CBuffer, CBufferBuilder
from nanoarrow.c_array_stream import c_array_stream
from nanoarrow.c_schema import c_schema_view
from nanoarrow.extension import resolve_extension
from nanoarrow.iterator import ArrayViewBaseIterator, PyIterator
from nanoarrow.schema import Type

Expand Down Expand Up @@ -428,9 +429,16 @@ def finish(self) -> Any:

def _resolve_converter_cls(schema, handle_nulls=None):
schema_view = c_schema_view(schema)
ext = resolve_extension(schema_view)
ext_converter_cls = ext.get_sequence_converter_cls(schema) if ext else None

if schema_view.nullable:
if schema_view.type_id == _types.BOOL:
if ext_converter_cls:
return ToNullableSequenceConverter, {
"converter_cls": ext_converter_cls,
"handle_nulls": handle_nulls,
}
elif schema_view.type_id == _types.BOOL:
return ToNullableSequenceConverter, {
"converter_cls": ToBooleanBufferConverter,
"handle_nulls": handle_nulls,
Expand All @@ -443,8 +451,9 @@ def _resolve_converter_cls(schema, handle_nulls=None):
else:
return ToPyListConverter, {}
else:

if schema_view.type_id == _types.BOOL:
if ext_converter_cls:
return ext_converter_cls, {}
elif schema_view.type_id == _types.BOOL:
return ToBooleanBufferConverter, {}
elif schema_view.buffer_format is not None:
return ToPyBufferConverter, {}
Expand Down

0 comments on commit c5a952d

Please sign in to comment.