This is an automated email from the ASF dual-hosted git repository.

mbrobbel pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 0d32de661c Update `UnionArray` wording to 'non-negative' (#8434)
0d32de661c is described below

commit 0d32de661c26f226db6a2a063a698fde33d7a023
Author: Jack <[email protected]>
AuthorDate: Thu Sep 25 11:08:55 2025 +0100

    Update `UnionArray` wording to 'non-negative' (#8434)
    
    # Which issue does this PR close?
    
    Closes https://github.com/apache/arrow-rs/issues/8418
    
    # Rationale for this change
    
    The "Safety" section mentions that `type_ids` are used to index into
    arrays, this means that values of 0 are also valid as this is the first
    element.
    
    The same is also true for `offsets`. There is a check within the
    `UnionArray::try_new` that is validating that `offset` is not less than
    0 (the value is not negative), otherwise an [error is
    
returned](https://github.com/apache/arrow-rs/blob/f7ea0aa815d24ab1cf66bfebe92c4c85f891e4d1/arrow-array/src/array/union_array.rs#L230-L235).
    
    # What changes are included in this PR?
    
    Documentation/wording changes
    
    # Are these changes tested?
    
    N/A, documentation only.
    
    # Are there any user-facing changes?
    
    N/A
---
 arrow-array/src/array/union_array.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arrow-array/src/array/union_array.rs 
b/arrow-array/src/array/union_array.rs
index d105876723..f974b9db18 100644
--- a/arrow-array/src/array/union_array.rs
+++ b/arrow-array/src/array/union_array.rs
@@ -137,11 +137,11 @@ impl UnionArray {
     ///
     /// # Safety
     ///
-    /// The `type_ids` values should be positive and must match one of the 
type ids of the fields provided in `fields`.
+    /// The `type_ids` values should be non-negative and must match one of the 
type ids of the fields provided in `fields`.
     /// These values are used to index into the `children` arrays.
     ///
     /// The `offsets` is provided in the case of a dense union, sparse unions 
should use `None`.
-    /// If provided the `offsets` values should be positive and must be less 
than the length of the
+    /// If provided the `offsets` values should be non-negative and must be 
less than the length of the
     /// corresponding array.
     ///
     /// In both cases above we use signed integer types to maintain 
compatibility with other
@@ -230,7 +230,7 @@ impl UnionArray {
             if iter.any(|(type_id, &offset)| offset < 0 || offset >= 
array_lens[*type_id as usize])
             {
                 return Err(ArrowError::InvalidArgumentError(
-                    "Offsets must be positive and within the length of the 
Array".to_owned(),
+                    "Offsets must be non-negative and within the length of the 
Array".to_owned(),
                 ));
             }
         }
@@ -1877,7 +1877,7 @@ mod tests {
 
         assert_eq!(
             err.to_string(),
-            "Invalid argument error: Offsets must be positive and within the 
length of the Array"
+            "Invalid argument error: Offsets must be non-negative and within 
the length of the Array"
         );
 
         let offsets = Some(vec![0, 1].into());

Reply via email to