Skip to content

Commit 53c0c23

Browse files
Rich-T-kidRichard Baah
andauthored
Docs: fix mutableArrayData comments (#10326)
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - Closes #9398. # Rationale for this change the comments on [arrow-rs/arrow-data/src/transform/mod.rs](https://github.com/apache/arrow-rs/blob/d6168e526aae79d6fbafe8c11062b5f834021052/arrow-data/src/transform/mod.rs#L389-L401) were misleading/incorrect <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? - updated DocTest to be accurate - updated `MutableArrayData::new()` to correctly use slots instead of bytes for allocation - see comment on issue -> #9398 (comment) <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> # Are these changes tested? yes <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? If this PR claims a performance improvement, please include evidence such as benchmark results. --> # Are there any user-facing changes? yes, users will have better doc comments. <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. --> --------- Co-authored-by: Richard Baah <richardbaah@MacBook-Air-de-Richard.local>
1 parent bc4e672 commit 53c0c23

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

  • arrow-data/src/transform

arrow-data/src/transform/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn build_extend_null_bits(array: &ArrayData, use_nulls: bool) -> ExtendNullBits<
118118
/// use arrow_data::transform::MutableArrayData;
119119
/// use arrow_schema::DataType;
120120
/// fn i32_array(values: &[i32]) -> ArrayData {
121-
/// ArrayData::try_new(DataType::Int32, 5, None, 0, vec![Buffer::from_slice_ref(values)], vec![]).unwrap()
121+
/// ArrayData::try_new(DataType::Int32, values.len(), None, 0, vec![Buffer::from_slice_ref(values)], vec![]).unwrap()
122122
/// }
123123
/// let arr1 = i32_array(&[1, 2, 3, 4, 5]);
124124
/// let arr2 = i32_array(&[6, 7, 8, 9, 10]);
@@ -128,7 +128,7 @@ fn build_extend_null_bits(array: &ArrayData, use_nulls: bool) -> ExtendNullBits<
128128
/// // Copy the first 3 elements from arr1
129129
/// mutable.extend(0, 0, 3);
130130
/// // Copy the last 3 elements from arr2
131-
/// mutable.extend(1, 2, 4);
131+
/// mutable.extend(1, 2, 5);
132132
/// // Complete the MutableArrayData into a new ArrayData
133133
/// let frozen = mutable.freeze();
134134
/// assert_eq!(frozen, i32_array(&[1, 2, 3, 8, 9, 10]));
@@ -397,13 +397,12 @@ impl<'a> MutableArrayData<'a> {
397397
///
398398
/// # Arguments
399399
/// * `arrays` - the source arrays to copy from
400-
/// * `use_nulls` - a flag used to optimize insertions
401-
/// - `false` if the only source of nulls are the arrays themselves
402-
/// - `true` if the user plans to call [MutableArrayData::extend_nulls].
403-
/// * capacity - the preallocated capacity of the output array, in bytes
400+
/// * `use_nulls` - a flag indicating whether the caller intends to call `extend_nulls`.
401+
/// Note: null-handling is enabled automatically if any source array contains nulls.
402+
/// * `capacity` - the preallocated capacity of the output array, in slots (number of elements)
404403
///
405-
/// Thus, if `use_nulls` is `false`, calling
406-
/// [MutableArrayData::extend_nulls] should not be used.
404+
/// if `use_nulls` is `false` and no source arrays contains nulls, calling
405+
/// [MutableArrayData::extend_nulls] or [MutableArrayData::try_extend_nulls] will panic.
407406
pub fn new(arrays: Vec<&'a ArrayData>, use_nulls: bool, capacity: usize) -> Self {
408407
Self::with_capacities(arrays, use_nulls, Capacities::Array(capacity))
409408
}

0 commit comments

Comments
 (0)