alamb commented on code in PR #5798:
URL: https://github.com/apache/arrow-rs/pull/5798#discussion_r1613557809


##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -766,23 +791,43 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
         PrimitiveArray::new(buffer.into(), nulls)
     }
 
-    /// Applies an unary and infallible function to a mutable primitive array.
-    /// Mutable primitive array means that the buffer is not shared with other 
arrays.
-    /// As a result, this mutates the buffer directly without allocating new 
buffer.
+    /// Applies a unary and infallible function to the array in place if 
possible.
+    ///
+    /// # Buffer Reuse
+    ///
+    /// If the underlying buffers are not shared with other arrays,  mutates 
the
+    /// underlying buffer in place, without allocating.
+    ///
+    /// # Null Handling
     ///
-    /// # Implementation
+    /// See [`Self::unary`] for more information on null handling.
     ///
-    /// This will apply the function for all values, including those on null 
slots.
-    /// This implies that the operation must be infallible for any value of 
the corresponding type
-    /// or this function may panic.
     /// # Example
+    ///
     /// ```rust
     /// # use arrow_array::{Int32Array, types::Int32Type};
-    /// # fn main() {
     /// let array = Int32Array::from(vec![Some(5), Some(7), None]);
+    /// // Apply x*2+1 to the data in place, no allocations
+    /// let c = array.unary_mut(|x| x * 2 + 1).unwrap();
+    /// assert_eq!(c, Int32Array::from(vec![Some(11), Some(15), None]));
+    /// ```
+    ///
+    /// # Example: modify [`ArrayRef`] in place, if not shared
+    ///
+    /// It is also possible to modify an [`ArrayRef`] if there are no other
+    /// references to the underlying buffer.
+    ///
+    /// ```rust
+    /// # use std::sync::Arc;
+    /// # use arrow_array::{Array, ArrayRef, Int32Array, PrimitiveArray, 
types::Int32Type};
+    /// # let array: ArrayRef = Arc::new(Int32Array::from(vec![Some(5), 
Some(7), None]));
+    /// // Convert to Int32Array (panic's if array.data_type is not Int32)
+    /// let array = PrimitiveArray::<Int32Type>::from(array.into_data());
+    /// // Apply x*2+1 to the data in place, no allocations if
+    /// // there are no other references to the underlying buffer
+    /// // will create a new buffer if there are references.

Review Comment:
   Good call, will fix



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to