Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/barak1412/polars into expos…
Browse files Browse the repository at this point in the history
…e_regex_escape
  • Loading branch information
barak1412 committed Oct 18, 2024
2 parents 32e4daa + f6b56c9 commit 622d233
Show file tree
Hide file tree
Showing 146 changed files with 2,666 additions and 1,711 deletions.
46 changes: 24 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions crates/polars-arrow/src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,49 @@ impl<O: Offset> ListArray<O> {
impl_sliced!();
impl_mut_validity!();
impl_into_array!();

pub fn trim_to_normalized_offsets_recursive(&self) -> Self {
let offsets = self.offsets();
let values = self.values();

let first_idx = *offsets.first();
let len = offsets.range().to_usize();

if first_idx.to_usize() == 0 && values.len() == len {
return self.clone();
}

let offsets = if first_idx.to_usize() == 0 {
offsets.clone()
} else {
let v = offsets.iter().map(|x| *x - first_idx).collect::<Vec<_>>();
unsafe { OffsetsBuffer::<O>::new_unchecked(v.into()) }
};

let values = values.sliced(first_idx.to_usize(), len);

let values = match values.dtype() {
ArrowDataType::List(_) => {
let inner: &ListArray<i32> = values.as_ref().as_any().downcast_ref().unwrap();
Box::new(inner.trim_to_normalized_offsets_recursive()) as Box<dyn Array>
},
ArrowDataType::LargeList(_) => {
let inner: &ListArray<i64> = values.as_ref().as_any().downcast_ref().unwrap();
Box::new(inner.trim_to_normalized_offsets_recursive()) as Box<dyn Array>
},
_ => values,
};

assert_eq!(offsets.first().to_usize(), 0);
assert_eq!(values.len(), offsets.range().to_usize());

Self::new(
self.dtype().clone(),
offsets,
values,
self.validity().cloned(),
)
}
}

// Accessors
Expand Down
15 changes: 1 addition & 14 deletions crates/polars-arrow/src/compute/aggregate/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use polars_error::PolarsResult;
use crate::array::{Array, PrimitiveArray};
use crate::bitmap::utils::{BitChunkIterExact, BitChunksExact};
use crate::bitmap::Bitmap;
use crate::datatypes::{ArrowDataType, PhysicalType, PrimitiveType};
use crate::datatypes::PhysicalType;
use crate::scalar::*;
use crate::types::simd::*;
use crate::types::NativeType;
Expand Down Expand Up @@ -102,19 +102,6 @@ where
}
}

/// Whether [`sum`] supports `dtype`
pub fn can_sum(dtype: &ArrowDataType) -> bool {
if let PhysicalType::Primitive(primitive) = dtype.to_physical_type() {
use PrimitiveType::*;
matches!(
primitive,
Int8 | Int16 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | Float32 | Float64
)
} else {
false
}
}

/// Returns the sum of all elements in `array` as a [`Scalar`] of the same physical
/// and logical types as `array`.
/// # Error
Expand Down
Loading

0 comments on commit 622d233

Please sign in to comment.