alamb commented on code in PR #6928:
URL: https://github.com/apache/arrow-rs/pull/6928#discussion_r1903129864
##########
arrow-select/src/zip.rs:
##########
@@ -15,20 +15,45 @@
// specific language governing permissions and limitations
// under the License.
-//! Zip two arrays by some boolean mask. Where the mask evaluates `true`
values of `truthy`
+//! [`zip`]: Combine values from two arrays based on boolean mask
use crate::filter::SlicesIterator;
use arrow_array::*;
use arrow_data::transform::MutableArrayData;
use arrow_schema::ArrowError;
-/// Zip two arrays by some boolean mask. Where the mask evaluates `true`
values of `truthy`
-/// are taken, where the mask evaluates `false` values of `falsy` are taken.
+/// Zip two arrays by some boolean mask.
+///
+/// - Where `mask` is `true`, values of `truthy` are taken
+/// - Where `mask` is `false` or `NULL`, values of `falsy` are taken
+///
+/// # Example
+/// ```
+/// # use std::sync::Arc;
+/// # use arrow_array::{ArrayRef, BooleanArray, Int32Array};
+/// # use arrow_select::zip::zip;
+/// // mask: [true, true, false, NULL, true]
+/// let mask = BooleanArray::from(vec![
+/// Some(true), Some(true), Some(false), None, Some(true)
+/// ]);
+/// // truthy array: [1, NULL, 3, 4, 5]
+/// let truthy = Int32Array::from(vec![
+/// Some(1), None, Some(3), Some(4), Some(5)
+/// ]);
+/// // falsy array: [10, 20, 30, 40, 50]
+/// let falsy = Int32Array::from(vec![
+/// Some(10), Some(20), Some(30), Some(40), Some(50)
+/// ]);
+/// // zip with this mask select the first, second and last value from `truthy`
+/// // and the third and fourth value from `falsy`
+/// let result = zip(&mask, &truthy, &falsy).unwrap();
+/// // Expected: [1, NULL, 30, 40, 5]
+/// let expected: ArrayRef = Arc::new(Int32Array::from(vec![
+/// Some(1), None, Some(30), Some(40), Some(5)
+/// ]));
+/// assert_eq!(&result, &expected);
Review Comment:
> Would it be necessary to add details on how Scalars interact with this
kernel, or is that unnecessary as that should be implied via knowledge of how
Scalars behave in general?
I think in theory it should be implied but I also think it might not be
obvious how it works / scalar is not as widely used / supported so I also
added a new example use of scalars (to fill in certain elements with a constant)
--
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]