danepitkin commented on code in PR #391:
URL: https://github.com/apache/arrow-nanoarrow/pull/391#discussion_r1499995897


##########
python/tests/test_c_buffer_view.py:
##########
@@ -0,0 +1,103 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+
+import nanoarrow as na
+from nanoarrow.c_lib import c_array_view
+
+
+def test_buffer_view_bool():
+    bool_array_view = c_array_view([1, 0, 0, 1], na.bool())
+    view = bool_array_view.buffer(1)
+
+    assert view.element_size_bits == 1
+    assert view.size_bytes == 1
+    assert view.data_type_id == na.Type.BOOL.value
+    assert view.data_type == "bool"
+    assert view.format == "B"
+
+    # Check item interface
+    assert len(view) == 1
+    assert view[0] == 1 + 8

Review Comment:
   nit: i'd prefer `0b1001` for readability. It took me a sec to realize what 
`1 + 8` meant haha



##########
python/src/nanoarrow/_lib.pyx:
##########
@@ -861,6 +867,27 @@ cdef class CSchemaView:
         return _repr_utils.schema_view_repr(self)
 
 
+cdef class CLayout:
+    cdef ArrowLayout* _layout
+    cdef object _base
+
+    def __cinit__(self, base, uintptr_t ptr):
+        self._base = base
+        self._layout = <ArrowLayout*>ptr
+
+    @property
+    def buffer_data_type_id(self):
+        return tuple(self._layout.buffer_data_type[i] for i in range(3))

Review Comment:
   Can we define the magic number 3 as a constant or variable somewhere? (or 
better yet, is it possible to take the `len()` of some object?)



##########
python/tests/test_c_buffer_view.py:
##########
@@ -0,0 +1,103 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+
+import nanoarrow as na
+from nanoarrow.c_lib import c_array_view
+
+
+def test_buffer_view_bool():
+    bool_array_view = c_array_view([1, 0, 0, 1], na.bool())
+    view = bool_array_view.buffer(1)
+
+    assert view.element_size_bits == 1
+    assert view.size_bytes == 1
+    assert view.data_type_id == na.Type.BOOL.value
+    assert view.data_type == "bool"
+    assert view.format == "B"
+
+    # Check item interface
+    assert len(view) == 1
+    assert view[0] == 1 + 8
+    assert list(view) == [1 + 8]
+
+    # Check against buffer protocol
+    mv = memoryview(view)
+    assert len(mv) == len(view)
+    assert mv[0] == view[0]
+    assert list(mv) == list(view)
+
+    # Check element interface
+    assert view.n_elements == 8
+    assert list(view.elements()) == [True, False, False, True] + [False] * 4
+    assert [view.element(i) for i in range(8)] == list(view.elements())
+
+    # Check element slices
+    assert list(view.elements(0, 4)) == [True, False, False, True]
+    assert list(view.elements(1, 3)) == [False, False, True]
+
+    with pytest.raises(IndexError, match="do not describe a valid slice"):

Review Comment:
   nit: I like to define static variables like strings once e.g. `msg = 
"<msg>"; with ... match=msg`



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