Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions arrow-array/src/array/boolean_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,20 @@ impl BooleanArray {

/// Returns the boolean value at index `i`.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
Comment on lines +181 to +182
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places, is it guaranteed not to panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is guaranteed not to panic.

///
/// # Safety
/// This doesn't check bounds, the caller must ensure that index < self.len()
pub unsafe fn value_unchecked(&self, i: usize) -> bool {
self.values.value_unchecked(i)
}

/// Returns the boolean value at index `i`.
///
/// Note: This method does not check for nulls and the value is arbitrary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually I think all value methods on all arrays behaves like this.

Copy link
Contributor Author

@alamb alamb Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, that is why i was trying to add the documentation.

/// if [`is_null`](Self::is_null) returns true for the index.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this calls value_unchecked actually, do we also want to add the note to value_unchecked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is an excellent call. I have done so

///
/// # Panics
/// Panics if index `i` is out of bounds
pub fn value(&self, i: usize) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions arrow-array/src/array/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ impl<T: ByteArrayType> GenericByteArray<T> {
}

/// Returns the element at index `i`
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places, is it guaranteed not to panic and return a valid T::Native value corresponding to type T (in (theoretical?) case T::Native could represent some values not valid for T)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places, is it guaranteed not to panic and return a valid T::Native value corresponding to type T

Yes, to the best of my knowledge

(in (theoretical?) case T::Native could represent some values not valid for T)

Yes I think this is possible -- the only one I can think of now is potentially date/time types where some valid integer is not a valid date/time/timestamp instance.

///
/// # Safety
/// Caller is responsible for ensuring that the index is within the bounds of the array
pub unsafe fn value_unchecked(&self, i: usize) -> &T::Native {
Expand Down Expand Up @@ -304,6 +308,10 @@ impl<T: ByteArrayType> GenericByteArray<T> {
}

/// Returns the element at index `i`
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds.
pub fn value(&self, i: usize) -> &T::Native {
Expand Down
7 changes: 7 additions & 0 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
}

/// Returns the element at index `i`
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds.
pub fn value(&self, i: usize) -> &T::Native {
Expand All @@ -312,6 +316,9 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {

/// Returns the element at index `i` without bounds checking
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Safety
///
/// Caller is responsible for ensuring that the index is within the bounds
Expand Down
12 changes: 11 additions & 1 deletion arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ impl FixedSizeBinaryArray {
}

/// Returns the element at index `i` as a byte slice.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds.
pub fn value(&self, i: usize) -> &[u8] {
Expand All @@ -155,8 +159,14 @@ impl FixedSizeBinaryArray {
}

/// Returns the element at index `i` as a byte slice.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Safety
/// Caller is responsible for ensuring that the index is within the bounds of the array
///
/// Caller is responsible for ensuring that the index is within the bounds
/// of the array
pub unsafe fn value_unchecked(&self, i: usize) -> &[u8] {
let offset = i + self.offset();
let pos = self.value_offset_at(offset);
Expand Down
6 changes: 6 additions & 0 deletions arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ impl FixedSizeListArray {
}

/// Returns ith value of this list array.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but still well-defined

should this be construed as meaning the returned value is of size L, if self is a FixedSizeList(L)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

///
/// # Panics
/// Panics if index `i` is out of bounds
pub fn value(&self, i: usize) -> ArrayRef {
self.values
.slice(self.value_offset_at(i), self.value_length() as usize)
Expand Down
10 changes: 10 additions & 0 deletions arrow-array/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
}

/// Returns ith value of this list array.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Safety
/// Caller must ensure that the index is within the array bounds
pub unsafe fn value_unchecked(&self, i: usize) -> ArrayRef {
Expand All @@ -336,6 +340,12 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
}

/// Returns ith value of this list array.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds
pub fn value(&self, i: usize) -> ArrayRef {
let end = self.value_offsets()[i + 1].as_usize();
let start = self.value_offsets()[i].as_usize();
Expand Down
8 changes: 8 additions & 0 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
}

/// Returns ith value of this list view array.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Safety
/// Caller must ensure that the index is within the array bounds
pub unsafe fn value_unchecked(&self, i: usize) -> ArrayRef {
Expand All @@ -292,6 +296,10 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
}

/// Returns ith value of this list view array.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if the index is out of bounds
pub fn value(&self, i: usize) -> ArrayRef {
Expand Down
9 changes: 9 additions & 0 deletions arrow-array/src/array/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ impl MapArray {

/// Returns ith value of this map array.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Safety
/// Caller must ensure that the index is within the array bounds
pub unsafe fn value_unchecked(&self, i: usize) -> StructArray {
Expand All @@ -197,6 +200,12 @@ impl MapArray {
/// Returns ith value of this map array.
///
/// This is a [`StructArray`] containing two fields
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds
pub fn value(&self, i: usize) -> StructArray {
let end = self.value_offsets()[i + 1] as usize;
let start = self.value_offsets()[i] as usize;
Expand Down
17 changes: 17 additions & 0 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {

/// Returns the primitive value at index `i`.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Safety
///
/// caller must ensure that the passed in offset is less than the array len()
Expand All @@ -729,6 +732,10 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
}

/// Returns the primitive value at index `i`.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds
#[inline]
Expand Down Expand Up @@ -1235,6 +1242,8 @@ where
///
/// If a data type cannot be converted to `NaiveDateTime`, a `None` is returned.
/// A valid value is expected, thus the user should first check for validity.
///
/// See notes on [`PrimitiveArray::value`] regarding nulls and panics
pub fn value_as_datetime(&self, i: usize) -> Option<NaiveDateTime> {
as_datetime::<T>(i64::from(self.value(i)))
}
Expand All @@ -1243,27 +1252,35 @@ where
///
/// functionally it is same as `value_as_datetime`, however it adds
/// the passed tz to the to-be-returned NaiveDateTime
///
/// See notes on [`PrimitiveArray::value`] regarding nulls and panics
pub fn value_as_datetime_with_tz(&self, i: usize, tz: Tz) -> Option<DateTime<Tz>> {
as_datetime_with_timezone::<T>(i64::from(self.value(i)), tz)
}

/// Returns value as a chrono `NaiveDate` by using `Self::datetime()`
///
/// If a data type cannot be converted to `NaiveDate`, a `None` is returned
///
/// See notes on [`PrimitiveArray::value`] regarding nulls and panics
pub fn value_as_date(&self, i: usize) -> Option<NaiveDate> {
self.value_as_datetime(i).map(|datetime| datetime.date())
}

/// Returns a value as a chrono `NaiveTime`
///
/// `Date32` and `Date64` return UTC midnight as they do not have time resolution
///
/// See notes on [`PrimitiveArray::value`] regarding nulls and panics
pub fn value_as_time(&self, i: usize) -> Option<NaiveTime> {
as_time::<T>(i64::from(self.value(i)))
}

/// Returns a value as a chrono `Duration`
///
/// If a data type cannot be converted to `Duration`, a `None` is returned
///
/// See notes on [`PrimitiveArray::value`] regarding nulls and panics
pub fn value_as_duration(&self, i: usize) -> Option<Duration> {
as_duration::<T>(i64::from(self.value(i)))
}
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/union_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ impl UnionArray {
}

/// Returns the array's value at index `i`.
///
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// Panics if index `i` is out of bounds
pub fn value(&self, i: usize) -> ArrayRef {
Expand Down
4 changes: 2 additions & 2 deletions parquet-variant-compute/src/variant_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl VariantArray {

/// Return the [`Variant`] instance stored at the given row
///
/// Consistently with other Arrow arrays types, this API requires you to
/// check for nulls first using [`Self::is_valid`].
/// Note: This method does not check for nulls and the value is arbitrary
/// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index.
///
/// # Panics
/// * if the index is out of bounds
Expand Down
Loading