joellubi commented on code in PR #43488:
URL: https://github.com/apache/arrow/pull/43488#discussion_r1705741285
##########
python/pyarrow/array.pxi:
##########
@@ -4447,6 +4447,69 @@ cdef class FixedShapeTensorArray(ExtensionArray):
FixedSizeListArray.from_arrays(values, shape[1:].prod())
)
+cdef class Bool8Array(ExtensionArray):
+ """
+ Concrete class for bool8 extension arrays.
+ Examples
+ --------
+ Define the extension type for an bool8 array
+ >>> import pyarrow as pa
+ >>> bool8_type = pa.bool8()
+ Create an extension array
+ >>> arr = [-1, 0, 1, 2, None]
+ >>> storage = pa.array(arr, pa.int8())
+ >>> pa.ExtensionArray.from_storage(bool8_type, storage)
+ <pyarrow.lib.Bool8Array object at ...>
+ [
+ -1,
+ 0,
+ 1,
+ 2,
+ null
+ ]
+ """
+
+ def to_numpy(self, zero_copy_only=True, writable=False):
+ try:
+ return self.storage.to_numpy().view(np.bool_)
+ except ArrowInvalid as e:
+ if zero_copy_only:
+ raise e
+
+ return _pc().not_equal(self.storage,
0).to_numpy(zero_copy_only=zero_copy_only, writable=writable)
Review Comment:
Yes, correct. The outcomes of taking the various paths are demonstrated in
[this
test](https://github.com/apache/arrow/pull/43488/files?diff=unified&w=0#diff-efc1a41cdf04b6ec96d822dbec1f1993e0bbd17050b1b5f1275c8e3443a38828R1716-R1742).
This also matches the existing semantics of converting a normal boolean
array to numpy, which currently performs a copy to an array of
`dtype=np.object_` if there are any missing values.
--
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]