This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 885461eb361 Document UnionArray Panics (#5456)
885461eb361 is described below
commit 885461eb361c1c3feccb990adb1c19d3f6aa9e53
Author: Kikkon <[email protected]>
AuthorDate: Mon Mar 4 02:48:21 2024 +0800
Document UnionArray Panics (#5456)
* Modifying comments to satisfy the function's expected behavior
* Update arrow-array/src/array/union_array.rs
Co-authored-by: Raphael Taylor-Davies
<[email protected]>
* Update arrow-array/src/array/union_array.rs
Co-authored-by: Raphael Taylor-Davies
<[email protected]>
---------
Co-authored-by: Raphael Taylor-Davies
<[email protected]>
---
arrow-array/src/array/union_array.rs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arrow-array/src/array/union_array.rs
b/arrow-array/src/array/union_array.rs
index 94ac0bc879e..63e927fd08a 100644
--- a/arrow-array/src/array/union_array.rs
+++ b/arrow-array/src/array/union_array.rs
@@ -226,9 +226,10 @@ impl UnionArray {
///
/// # Panics
///
- /// Panics if the `type_id` provided is less than zero or greater than the
number of types
+ /// Panics if the `type_id` provided is not present in the array's DataType
/// in the `Union`.
pub fn child(&self, type_id: i8) -> &ArrayRef {
+ assert!((type_id as usize) < self.fields.len());
let boxed = &self.fields[type_id as usize];
boxed.as_ref().expect("invalid type id")
}
@@ -237,8 +238,9 @@ impl UnionArray {
///
/// # Panics
///
- /// Panics if `index` is greater than the length of the array.
+ /// Panics if `index` is greater than or equal to the number of child
arrays
pub fn type_id(&self, index: usize) -> i8 {
+ assert!(index < self.type_ids.len());
self.type_ids[index]
}
@@ -256,7 +258,7 @@ impl UnionArray {
///
/// # Panics
///
- /// Panics if `index` is greater than the length of the array.
+ /// Panics if `index` is greater than or equal the length of the array.
pub fn value_offset(&self, index: usize) -> usize {
assert!(index < self.len());
match &self.offsets {