Skip to content

Commit

Permalink
fix(rust): Fix inconsistency between code and comment (#21294)
Browse files Browse the repository at this point in the history
  • Loading branch information
YichiZhang0613 authored Feb 17, 2025
1 parent 0c049c3 commit ab1f3c4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions crates/polars-arrow/src/array/growable/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ impl<'a, O: Offset> GrowableUtf8<'a, O> {
/// # Panics
/// If `arrays` is empty.
pub fn new(arrays: Vec<&'a Utf8Array<O>>, mut use_validity: bool, capacity: usize) -> Self {
assert!(!arrays.is_empty());

// if any of the arrays has nulls, insertions from any array requires setting bits
// as there is at least one array with nulls.
if arrays.iter().any(|array| array.null_count() > 0) {
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-arrow/src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl<O: Offset> ListArray<O> {
///
/// # Errors
/// This function returns an error iff:
/// * The last offset is not equal to the values' length.
/// * the validity's length is not equal to `offsets.len()`.
/// * `offsets.last()` is greater than `values.len()`.
/// * the validity's length is not equal to `offsets.len_proxy()`.
/// * The `dtype`'s [`crate::datatypes::PhysicalType`] is not equal to either [`crate::datatypes::PhysicalType::List`] or [`crate::datatypes::PhysicalType::LargeList`].
/// * The `dtype`'s inner field's data type is not equal to `values.dtype`.
/// # Implementation
Expand Down Expand Up @@ -66,8 +66,8 @@ impl<O: Offset> ListArray<O> {
///
/// # Panics
/// This function panics iff:
/// * The last offset is not equal to the values' length.
/// * the validity's length is not equal to `offsets.len()`.
/// * `offsets.last()` is greater than `values.len()`.
/// * the validity's length is not equal to `offsets.len_proxy()`.
/// * The `dtype`'s [`crate::datatypes::PhysicalType`] is not equal to either [`crate::datatypes::PhysicalType::List`] or [`crate::datatypes::PhysicalType::LargeList`].
/// * The `dtype`'s inner field's data type is not equal to `values.dtype`.
/// # Implementation
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/array/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl MapArray {
/// Returns a new [`MapArray`].
/// # Errors
/// This function errors iff:
/// * The last offset is not equal to the field' length
/// * `offsets.last()` is greater than `field.len()`
/// * The `dtype`'s physical type is not [`crate::datatypes::PhysicalType::Map`]
/// * The fields' `dtype` is not equal to the inner field of `dtype`
/// * The validity is not `None` and its length is different from `offsets.len() - 1`.
Expand Down Expand Up @@ -66,7 +66,7 @@ impl MapArray {

/// Creates a new [`MapArray`].
/// # Panics
/// * The last offset is not equal to the field' length.
/// * `offsets.last()` is greater than `field.len()`.
/// * The `dtype`'s physical type is not [`crate::datatypes::PhysicalType::Map`],
/// * The validity is not `None` and its length is different from `offsets.len() - 1`.
pub fn new(
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/array/struct_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl StructArray {

/// Slices this [`StructArray`].
/// # Panics
/// * `offset + length` must be smaller than `self.len()`.
/// panics iff `offset + length > self.len()`
/// # Implementation
/// This operation is `O(F)` where `F` is the number of fields.
pub fn slice(&mut self, offset: usize, length: usize) {
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl<O: Offset> Utf8Array<O> {
/// Creates a new [`Utf8Array`].
/// # Panics
/// This function panics iff:
/// * The last offset is greater than the values' length.
/// * `offsets.last()` is greater than `values.len()`.
/// * the validity's length is not equal to `offsets.len_proxy()`.
/// * The `dtype`'s [`crate::datatypes::PhysicalType`] is not equal to either `Utf8` or `LargeUtf8`.
/// * The `values` between two consecutive `offsets` are not valid utf8
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/array/utf8/mutable_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<O: Offset> MutableUtf8ValuesArray<O> {
///
/// # Errors
/// This function returns an error iff:
/// * The last offset is not equal to the values' length.
/// * `offsets.last()` is greater than `values.len()`.
/// * The `dtype`'s [`crate::datatypes::PhysicalType`] is not equal to either `Utf8` or `LargeUtf8`.
/// * The `values` between two consecutive `offsets` are not valid utf8
/// # Implementation
Expand All @@ -92,7 +92,7 @@ impl<O: Offset> MutableUtf8ValuesArray<O> {
///
/// # Panic
/// This function does not panic iff:
/// * The last offset is equal to the values' length.
/// * `offsets.last()` is greater than `values.len()`
/// * The `dtype`'s [`crate::datatypes::PhysicalType`] is equal to either `Utf8` or `LargeUtf8`.
///
/// # Safety
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl Bitmap {

/// Creates a new [`Bitmap`] from a slice and length.
/// # Panic
/// Panics iff `length <= bytes.len() * 8`
/// Panics iff `length > bytes.len() * 8`
#[inline]
pub fn from_u8_slice<T: AsRef<[u8]>>(slice: T, length: usize) -> Self {
Bitmap::try_new(slice.as_ref().to_vec(), length).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<O: Offset> Offsets<O> {

/// Returns a `length` corresponding to the position `index`
/// # Panic
/// This function panics iff `index >= self.len()`
/// This function panics iff `index >= self.len_proxy()`
#[inline]
pub fn length_at(&self, index: usize) -> usize {
let (start, end) = self.start_end(index);
Expand Down

0 comments on commit ab1f3c4

Please sign in to comment.