paleolimbot commented on code in PR #340:
URL: https://github.com/apache/arrow-nanoarrow/pull/340#discussion_r1447981591


##########
python/src/nanoarrow/_lib.pyx:
##########
@@ -630,65 +574,71 @@ cdef class Array:
 
     @property
     def null_count(self):
+        self._assert_valid()
         return self._ptr.null_count
 
+    @property
+    def n_buffers(self):
+        self._assert_valid()
+        return self._ptr.n_buffers
+
     @property
     def buffers(self):
+        self._assert_valid()
         return tuple(<uintptr_t>self._ptr.buffers[i] for i in 
range(self._ptr.n_buffers))
 
+    @property
+    def n_children(self):
+        self._assert_valid()
+        return self._ptr.n_children
+
+    def child(self, int64_t i):
+        self._assert_valid()
+        if i < 0 or i >= self._ptr.n_children:
+            raise IndexError(f"{i} out of range [0, {self._ptr.n_children})")
+        return CArray(self._base, <uintptr_t>self._ptr.children[i], 
self._schema.child(i))
+
     @property
     def children(self):
-        return ArrayChildren(self)
+        for i in range(self.n_children):
+            yield self.child(i)
 
     @property
     def dictionary(self):
         self._assert_valid()
         if self._ptr.dictionary != NULL:
-            return Array(self, <uintptr_t>self._ptr.dictionary, 
self._schema.dictionary)
+            return CArray(self, <uintptr_t>self._ptr.dictionary, 
self._schema.dictionary)
         else:
             return None
 
     def __repr__(self):
-        return array_repr(self)
-
-
-cdef class ArrayView:
-    """ArrowArrayView wrapper
-
-    The ArrowArrayView is a nanoarrow C library structure that provides
-    structured access to buffers addresses, buffer sizes, and buffer
-    data types. The buffer data is usually propagated from an ArrowArray
-    but can also be propagated from other types of objects (e.g., serialized
-    IPC). The offset and length of this view are independent of its parent
-    (i.e., this object can also represent a slice of its parent).
-
-    Examples
-    --------
-
-    >>> import pyarrow as pa
-    >>> import numpy as np
-    >>> import nanoarrow as na
-    >>> array = na.array(pa.array(["one", "two", "three", None]))
-    >>> array_view = na.array_view(array)
-    >>> np.array(array_view.buffers[1])
-    array([ 0,  3,  6, 11, 11], dtype=int32)
-    >>> np.array(array_view.buffers[2])
-    array([b'o', b'n', b'e', b't', b'w', b'o', b't', b'h', b'r', b'e', b'e'],
-          dtype='|S1')
+        return _lib_utils.array_repr(self)
+
+
+cdef class CArrayView:
+    """Low-level ArrowArrayView wrapper
+
+    This object is a literal wrapper around an ArrowArrayView. It provides 
field accessors
+    that return Python objects and handles the structure lifecycle (i.e., 
initialized
+    ArrowArrayView structures are always released).
+
+    See `nanoarrow.c_array_view()` for construction and usage examples.
     """
     cdef object _base
     cdef ArrowArrayView* _ptr
     cdef ArrowDevice* _device
-    cdef Schema _schema
-    cdef object _base_buffer
 
-    def __cinit__(self, object base, uintptr_t addr, Schema schema, object 
base_buffer):
+    def __cinit__(self, object base, uintptr_t addr):
         self._base = base
         self._ptr = <ArrowArrayView*>addr
-        self._schema = schema
-        self._base_buffer = base_buffer
         self._device = ArrowDeviceCpu()
 
+    @property
+    def storage_type(self):

Review Comment:
   For some values of `type` (dictionary, timestamp, time, duration, maybe 
others I'm forgetting), the `storage_type` is the lower-level type (e.g., for 
dictionary it would be the integer type, for timestamp it would be int64, 
etc.). The C definition of the `ArrowArrayView` could arguably also emebed a 
`ArrowSchemaView` but it's never come up.



-- 
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]

Reply via email to