danepitkin commented on code in PR #396:
URL: https://github.com/apache/arrow-nanoarrow/pull/396#discussion_r1524992869
##########
python/src/nanoarrow/_lib.pyx:
##########
@@ -2198,6 +2200,130 @@ cdef class CArrayStream:
return _repr_utils.array_stream_repr(self)
+cdef class CMaterializedArrayStream:
+ cdef CSchema _schema
+ cdef CBuffer _array_ends
+ cdef list _arrays
+ cdef int64_t _total_length
+
+ def __cinit__(self):
+ self._arrays = []
+ self._total_length = 0
+ self._schema = CSchema.allocate()
+ self._array_ends = CBuffer.empty()
+ cdef int code = ArrowBufferAppendInt64(self._array_ends._ptr, 0)
+ Error.raise_error_not_ok("ArrowBufferAppendInt64()", code)
+
+ cdef _finalize(self):
+ self._array_ends._set_data_type(NANOARROW_TYPE_INT64)
+
+ @property
+ def schema(self):
+ return self._schema
+
+ @property
+ def array_ends(self):
+ return self._array_ends
+
+ def __getitem__(self, k):
+ cdef int64_t kint
+ cdef int array_i
+ cdef const int64_t* sorted_offsets =
<int64_t*>self._array_ends._ptr.data
+
+ if not isinstance(k, slice):
+ kint = k
+ if kint < 0:
+ kint += self._total_length
+ if kint < 0 or kint >= self._total_length:
+ raise IndexError(f"Index {kint} is out of range")
+
+ array_i = ArrowResolveChunk64(kint, sorted_offsets, 0,
len(self._arrays))
+ kint -= sorted_offsets[array_i]
+ return self._arrays[array_i], kint
+
+ raise NotImplementedError("index with slice")
+
+ def __len__(self):
+ return self._array_ends[len(self._arrays)]
+
+ def __iter__(self):
+ for c_array in self._arrays:
+ for item_i in range(c_array.length):
+ yield c_array, item_i
+
+ def array(self, int64_t i):
+ return self._arrays[i]
+
+ @property
+ def n_arrays(self):
Review Comment:
No worries, if there's already a precedent then you can ignore me. n_* isn't
bad either
--
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]