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


##########
arrow-array/src/array/mod.rs:
##########
@@ -196,6 +198,28 @@ pub trait Array: std::fmt::Debug + Send + Sync {
     /// use the slower [`Array::logical_nulls`] to obtain a computed mask.
     fn nulls(&self) -> Option<&NullBuffer>;
 
+    /// Replaces the nulls of this array.
+    ///
+    /// # Panics
+    /// Panics if the length of the null buffer is not equal to the length of 
the array.
+    ///
+    /// # Example:
+    /// ```
+    /// # use arrow_array::{Array, Int32Array};
+    /// # use arrow_array::cast::AsArray;
+    /// # use arrow_buffer::NullBuffer;
+    /// // Create an array with values [1, null, 3, 4, 5]
+    /// let array = Int32Array::from(vec![Some(1), None, Some(3), Some(4), 
Some(5)]);
+    /// // Set the first, third, and fifth elements to null, others to valid
+    /// let nulls = Some(NullBuffer::from(vec![false, true, false, true, 
false]));
+    /// let array_with_nulls = array.with_nulls(nulls);
+    /// assert_eq!(
+    ///   array_with_nulls.as_primitive(),
+    ///   &Int32Array::from(vec![None, Some(0), None, Some(4), None]),

Review Comment:
   the fact that this is now `Some(0)` (whatever value was created for the 
`null` element in the original array) could have potential issues 🤔 



##########
arrow-array/src/array/mod.rs:
##########
@@ -196,6 +198,28 @@ pub trait Array: std::fmt::Debug + Send + Sync {
     /// use the slower [`Array::logical_nulls`] to obtain a computed mask.
     fn nulls(&self) -> Option<&NullBuffer>;
 
+    /// Replaces the nulls of this array.
+    ///
+    /// # Panics
+    /// Panics if the length of the null buffer is not equal to the length of 
the array.
+    ///
+    /// # Example:
+    /// ```
+    /// # use arrow_array::{Array, Int32Array};

Review Comment:
   Here is the new API and an example. I am not sure this is a good idea due to 
@tustvold 's comment here: 
https://github.com/apache/arrow-rs/issues/6528#issuecomment-2401522424 but 
figured I would make a PR for discussion (and only now do I really understand 
what he is talking about)



-- 
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