apache / arrow-nanoarrow

Helpers for Arrow C Data & Arrow C Stream interfaces
https://arrow.apache.org/nanoarrow
Apache License 2.0
169 stars 35 forks source link

feat(python): Ensure that buffer produced by `CBufferView.unpack_bits()` has a boolean type #457

Closed paleolimbot closed 4 months ago

paleolimbot commented 4 months ago

This is small change to ensure that np.array(some_buffer.unpack_bits()) "just works" without nanoarrow having to know about numpy dtypes. Basically we just need to ensure that we can create/export a buffer with a "?" format string.

import nanoarrow as na
import numpy as np

bool_array = na.Array([True, True, True, False, False, True], na.bool_())
np.array(bool_array.buffer(1).unpack_bits(0, len(bool_array)))
#> array([ True,  True,  True, False, False,  True])