Skip to content

Commit

Permalink
refactor(rust): Rename ChunkedArray.chunk_id to chunk_lengths (po…
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored and Wouittone committed Jun 22, 2024
1 parent e768cf3 commit d231cfe
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 57 deletions.
6 changes: 3 additions & 3 deletions crates/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::utils::{first_non_null, last_non_null};
#[cfg(not(feature = "dtype-categorical"))]
pub struct RevMapping {}

pub type ChunkIdIter<'a> = std::iter::Map<std::slice::Iter<'a, ArrayRef>, fn(&ArrayRef) -> usize>;
pub type ChunkLenIter<'a> = std::iter::Map<std::slice::Iter<'a, ArrayRef>, fn(&ArrayRef) -> usize>;

/// # ChunkedArray
///
Expand Down Expand Up @@ -359,8 +359,8 @@ impl<T: PolarsDataType> ChunkedArray<T> {
Ok(unsafe { self.unpack_series_matching_physical_type(series) })
}

/// Unique id representing the number of chunks
pub fn chunk_id(&self) -> ChunkIdIter {
/// Returns an iterator over the lengths of the chunks of the array.
pub fn chunk_lengths(&self) -> ChunkLenIter {
self.chunks.iter().map(|chunk| chunk.len())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/chunked_array/ops/downcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<T: PolarsDataType> ChunkedArray<T> {
(1, index - len)
};
}
let chunk_lens = self.downcast_iter().map(|arr| arr.len());
let chunk_lens = self.chunk_lengths();
let len = self.len();
if index <= len / 2 {
// Access from lhs.
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use crate::chunked_array::ops::rolling_window::RollingOptionsFixedWindow;
pub use crate::chunked_array::ops::*;
#[cfg(feature = "temporal")]
pub use crate::chunked_array::temporal::conversion::*;
pub(crate) use crate::chunked_array::ChunkIdIter;
pub(crate) use crate::chunked_array::ChunkLenIter;
pub use crate::chunked_array::ChunkedArray;
#[cfg(feature = "dtype-categorical")]
pub use crate::datatypes::string_cache::StringCacheHolder;
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl SeriesTrait for SeriesWrap<ArrayChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl SeriesTrait for SeriesWrap<BinaryChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl SeriesTrait for SeriesWrap<BinaryOffsetChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl SeriesTrait for SeriesWrap<BooleanChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ impl SeriesTrait for SeriesWrap<CategoricalChunked> {
self.0.physical_mut().rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.physical().chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.physical().chunk_lengths()
}
fn name(&self) -> &str {
self.0.physical().name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/dates_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ macro_rules! impl_dyn_series {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ impl SeriesTrait for SeriesWrap<DatetimeChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ impl SeriesTrait for SeriesWrap<DecimalChunked> {
self.0.rename(name)
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}

fn name(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl SeriesTrait for SeriesWrap<DurationChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ macro_rules! impl_dyn_series {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl SeriesTrait for SeriesWrap<ListChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ macro_rules! impl_dyn_series {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/series/implementations/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl SeriesTrait for NullChunked {
&mut self.chunks
}

fn chunk_lengths(&self) -> ChunkIdIter {
fn chunk_lengths(&self) -> ChunkLenIter {
self.chunks.iter().map(|chunk| chunk.len())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ where
ObjectChunked::rename(&mut self.0, name)
}

fn chunk_lengths(&self) -> ChunkIdIter {
ObjectChunked::chunk_id(&self.0)
fn chunk_lengths(&self) -> ChunkLenIter {
ObjectChunked::chunk_lengths(&self.0)
}

fn name(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/series/implementations/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl SeriesTrait for SeriesWrap<StringChunked> {
self.0.rename(name);
}

fn chunk_lengths(&self) -> ChunkIdIter {
self.0.chunk_id()
fn chunk_lengths(&self) -> ChunkLenIter {
self.0.chunk_lengths()
}
fn name(&self) -> &str {
self.0.name()
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/series/implementations/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SeriesTrait for SeriesWrap<StructChunked> {
self.0.name()
}

fn chunk_lengths(&self) -> ChunkIdIter {
fn chunk_lengths(&self) -> ChunkLenIter {
let s = self.0.fields().first().unwrap();
s.chunk_lengths()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/series/series_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub trait SeriesTrait:
}

/// Get the lengths of the underlying chunks
fn chunk_lengths(&self) -> ChunkIdIter;
fn chunk_lengths(&self) -> ChunkLenIter;

/// Name of series.
fn name(&self) -> &str;
Expand Down
42 changes: 21 additions & 21 deletions crates/polars-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,13 @@ where
assert();
(
Cow::Borrowed(left),
Cow::Owned(right.match_chunks(left.chunk_id())),
Cow::Owned(right.match_chunks(left.chunk_lengths())),
)
},
(1, _) => {
assert();
(
Cow::Owned(left.match_chunks(right.chunk_id())),
Cow::Owned(left.match_chunks(right.chunk_lengths())),
Cow::Borrowed(right),
)
},
Expand All @@ -724,7 +724,7 @@ where
// could optimize to choose to rechunk a primitive and not a string or list type
let left = left.rechunk();
(
Cow::Owned(left.match_chunks(right.chunk_id())),
Cow::Owned(left.match_chunks(right.chunk_lengths())),
Cow::Borrowed(right),
)
},
Expand Down Expand Up @@ -786,50 +786,50 @@ where
match (a.chunks.len(), b.chunks.len(), c.chunks.len()) {
(_, 1, 1) => (
Cow::Borrowed(a),
Cow::Owned(b.match_chunks(a.chunk_id())),
Cow::Owned(c.match_chunks(a.chunk_id())),
Cow::Owned(b.match_chunks(a.chunk_lengths())),
Cow::Owned(c.match_chunks(a.chunk_lengths())),
),
(1, 1, _) => (
Cow::Owned(a.match_chunks(c.chunk_id())),
Cow::Owned(b.match_chunks(c.chunk_id())),
Cow::Owned(a.match_chunks(c.chunk_lengths())),
Cow::Owned(b.match_chunks(c.chunk_lengths())),
Cow::Borrowed(c),
),
(1, _, 1) => (
Cow::Owned(a.match_chunks(b.chunk_id())),
Cow::Owned(a.match_chunks(b.chunk_lengths())),
Cow::Borrowed(b),
Cow::Owned(c.match_chunks(b.chunk_id())),
Cow::Owned(c.match_chunks(b.chunk_lengths())),
),
(1, _, _) => {
let b = b.rechunk();
(
Cow::Owned(a.match_chunks(c.chunk_id())),
Cow::Owned(b.match_chunks(c.chunk_id())),
Cow::Owned(a.match_chunks(c.chunk_lengths())),
Cow::Owned(b.match_chunks(c.chunk_lengths())),
Cow::Borrowed(c),
)
},
(_, 1, _) => {
let a = a.rechunk();
(
Cow::Owned(a.match_chunks(c.chunk_id())),
Cow::Owned(b.match_chunks(c.chunk_id())),
Cow::Owned(a.match_chunks(c.chunk_lengths())),
Cow::Owned(b.match_chunks(c.chunk_lengths())),
Cow::Borrowed(c),
)
},
(_, _, 1) => {
let b = b.rechunk();
(
Cow::Borrowed(a),
Cow::Owned(b.match_chunks(a.chunk_id())),
Cow::Owned(c.match_chunks(a.chunk_id())),
Cow::Owned(b.match_chunks(a.chunk_lengths())),
Cow::Owned(c.match_chunks(a.chunk_lengths())),
)
},
_ => {
// could optimize to choose to rechunk a primitive and not a string or list type
let a = a.rechunk();
let b = b.rechunk();
(
Cow::Owned(a.match_chunks(c.chunk_id())),
Cow::Owned(b.match_chunks(c.chunk_id())),
Cow::Owned(a.match_chunks(c.chunk_lengths())),
Cow::Owned(b.match_chunks(c.chunk_lengths())),
Cow::Borrowed(c),
)
},
Expand Down Expand Up @@ -1051,8 +1051,8 @@ mod test {
b.append(&b2);
let (a, b) = align_chunks_binary(&a, &b);
assert_eq!(
a.chunk_id().collect::<Vec<_>>(),
b.chunk_id().collect::<Vec<_>>()
a.chunk_lengths().collect::<Vec<_>>(),
b.chunk_lengths().collect::<Vec<_>>()
);

let a = Int32Chunked::new("", &[1, 2, 3, 4]);
Expand All @@ -1063,8 +1063,8 @@ mod test {
b.append(&b1);
let (a, b) = align_chunks_binary(&a, &b);
assert_eq!(
a.chunk_id().collect::<Vec<_>>(),
b.chunk_id().collect::<Vec<_>>()
a.chunk_lengths().collect::<Vec<_>>(),
b.chunk_lengths().collect::<Vec<_>>()
);
}
}

0 comments on commit d231cfe

Please sign in to comment.