Skip to content

Commit 885461e

Browse files
Kikkontustvold
andauthored
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 <1781103+tustvold@users.noreply.github.com> * Update arrow-array/src/array/union_array.rs Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> --------- Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
1 parent c5ab64c commit 885461e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arrow-array/src/array/union_array.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ impl UnionArray {
226226
///
227227
/// # Panics
228228
///
229-
/// Panics if the `type_id` provided is less than zero or greater than the number of types
229+
/// Panics if the `type_id` provided is not present in the array's DataType
230230
/// in the `Union`.
231231
pub fn child(&self, type_id: i8) -> &ArrayRef {
232+
assert!((type_id as usize) < self.fields.len());
232233
let boxed = &self.fields[type_id as usize];
233234
boxed.as_ref().expect("invalid type id")
234235
}
@@ -237,8 +238,9 @@ impl UnionArray {
237238
///
238239
/// # Panics
239240
///
240-
/// Panics if `index` is greater than the length of the array.
241+
/// Panics if `index` is greater than or equal to the number of child arrays
241242
pub fn type_id(&self, index: usize) -> i8 {
243+
assert!(index < self.type_ids.len());
242244
self.type_ids[index]
243245
}
244246

@@ -256,7 +258,7 @@ impl UnionArray {
256258
///
257259
/// # Panics
258260
///
259-
/// Panics if `index` is greater than the length of the array.
261+
/// Panics if `index` is greater than or equal the length of the array.
260262
pub fn value_offset(&self, index: usize) -> usize {
261263
assert!(index < self.len());
262264
match &self.offsets {

0 commit comments

Comments
 (0)