Struct arrow2::array::BooleanArray

source ·
pub struct BooleanArray { /* private fields */ }
Expand description

A BooleanArray is Arrow’s semantically equivalent of an immutable Vec<Option<bool>>. It implements Array.

One way to think about a BooleanArray is (DataType, Arc<Vec<u8>>, Option<Arc<Vec<u8>>>) where:

  • the first item is the array’s logical type
  • the second is the immutable values
  • the third is the immutable validity (whether a value is null or not as a bitmap).

The size of this struct is O(1), as all data is stored behind an std::sync::Arc.

Example

use arrow2::array::BooleanArray;
use arrow2::bitmap::Bitmap;
use arrow2::buffer::Buffer;

let array = BooleanArray::from([Some(true), None, Some(false)]);
assert_eq!(array.value(0), true);
assert_eq!(array.iter().collect::<Vec<_>>(), vec![Some(true), None, Some(false)]);
assert_eq!(array.values_iter().collect::<Vec<_>>(), vec![true, false, false]);
// the underlying representation
assert_eq!(array.values(), &Bitmap::from([true, false, false]));
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));

Implementations§

The canonical method to create a BooleanArray out of low-end APIs.

Errors

This function errors iff:

Alias to Self::try_new().unwrap()

Returns an iterator over the optional values of this BooleanArray.

Returns an iterator over the values of this BooleanArray.

Returns the length of this array

The values Bitmap. Values on null slots are undetermined (they can be anything).

Returns the optional validity.

Returns the arrays’ DataType.

Returns the value at index i

Panic

This function panics iff i >= self.len().

Returns the element at index i as bool

Safety

Caller must be sure that i < self.len()

Returns a slice of this BooleanArray.

Implementation

This operation is O(1) as it amounts to increase up to two ref counts.

Panic

This function panics iff offset + length > self.len().

Returns a slice of this BooleanArray.

Implementation

This operation is O(1) as it amounts to increase two ref counts.

Safety

The caller must ensure that offset + length <= self.len().

Returns this BooleanArray with a new validity.

Panic

This function panics iff validity.len() != self.len().

Sets the validity of this BooleanArray.

Panics

This function panics iff values.len() != self.len().

Returns a clone of this BooleanArray with new values.

Panics

This function panics iff values.len() != self.len().

Sets the values of this BooleanArray.

Panics

This function panics iff values.len() != self.len().

Applies a function f to the values of this array, cloning the values iff they are being shared with others

This is an API to use clone-on-write

Implementation

This function is O(f) if the data is not being shared, and O(N) + O(f) if it is being shared (since it results in a O(N) memcopy).

Panics

This function panics if the function modifies the length of the MutableBitmap.

Try to convert this BooleanArray to a MutableBooleanArray

Returns a new empty BooleanArray.

Returns a new BooleanArray whose all slots are null / None.

Creates a new BooleanArray from an TrustedLen of bool.

Creates a new BooleanArray from an TrustedLen of bool. Use this over BooleanArray::from_trusted_len_iter when the iterator is trusted len but this crate does not mark it as such.

Safety

The iterator must be TrustedLen. I.e. that size_hint().1 correctly reports its length.

Creates a new BooleanArray from a slice of bool.

Creates a BooleanArray from an iterator of trusted length. Use this over BooleanArray::from_trusted_len_iter when the iterator is trusted len but this crate does not mark it as such.

Safety

The iterator must be TrustedLen. I.e. that size_hint().1 correctly reports its length.

Creates a BooleanArray from a TrustedLen.

Creates a BooleanArray from an falible iterator of trusted length.

Safety

The iterator must be TrustedLen. I.e. that size_hint().1 correctly reports its length.

Creates a BooleanArray from a TrustedLen.

Boxes self into a Box<dyn Array>.

Boxes self into a std::sync::Arc<dyn Array>.

Returns its internal representation

Trait Implementations§

Converts itself to a reference of Any, which enables downcasting to concrete types.
Converts itself to a mutable reference of Any, which enables mutable downcasting to concrete types.
The length of the Array. Every array has a length corresponding to the number of elements (slots).
The DataType of the Array. In combination with Array::as_any, this can be used to downcast trait objects (dyn Array) to concrete arrays.
The validity of the Array: every array has an optional Bitmap that, when available specifies whether the array slot is valid or not (null). When the validity is None, all slots are valid.
Slices the Array, returning a new Box<dyn Array>. Read more
Slices the Array, returning a new Box<dyn Array>. Read more
Clones this Array with a new new assigned bitmap. Read more
Clone a &dyn Array to an owned Box<dyn Array>.
whether the array is empty
The number of null slots on this Array. Read more
Returns whether slot i is null. Read more
Returns whether slot i is valid. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Turns an IntoIterator of references into a StreamingIterator. Read more
Turns an IntoIterator of mutable references into a StreamingIteratorMut. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.