paleolimbot commented on code in PR #464: URL: https://github.com/apache/arrow-nanoarrow/pull/464#discussion_r1605409844
########## python/src/nanoarrow/visitor.py: ########## @@ -15,68 +15,186 @@ # specific language governing permissions and limitations # under the License. -from typing import Any, List, Sequence, Tuple, Union +from typing import Any, Callable, List, Sequence, Tuple, Union -from nanoarrow._lib import CArrayView +from nanoarrow._lib import CArrayView, CArrowType, CBuffer, CBufferBuilder from nanoarrow.c_array_stream import c_array_stream +from nanoarrow.c_schema import c_schema_view from nanoarrow.iterator import ArrayViewBaseIterator, PyIterator from nanoarrow.schema import Type -def to_pylist(obj, schema=None) -> List: - """Convert ``obj`` to a ``list()` of Python objects +class ArrayViewVisitable: + """Mixin class providing conversion methods based on visitors - Computes an identical value to ``list(iterator.iter_py())`` but is several - times faster. + Can be used with classes that implement ``__arrow_c_stream__()`` + or ``__arrow_c_array__()``. + """ + + def to_pylist(self) -> List: + """Convert to a ``list`` of Python objects + + Computes an identical value to ``list(iter_py())`` but can be much + faster. + + Examples + -------- + >>> import nanoarrow as na + >>> from nanoarrow import visitor + >>> array = na.Array([1, 2, 3], na.int32()) + >>> array.to_pylist() + [1, 2, 3] + """ + return ListBuilder.visit(self) + + def to_column_list(self, handle_nulls=None) -> Tuple[List[str], List[Sequence]]: Review Comment: I went with `to_columns_pysequence()` for now...it's not *quite* a table and I am not sure inventing one here is the solution either. Unfortunately it's also the most useful function! Hopefully its usage will give some guidance as to what it should be named or if it needs to be removed/live somewhere else. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
