From d231cfe2c329c86ed7fad2839d98e9f3375661fa Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 17 May 2024 08:40:27 +0200 Subject: [PATCH] refactor(rust): Rename `ChunkedArray.chunk_id` to `chunk_lengths` (#16273) --- crates/polars-core/src/chunked_array/mod.rs | 6 +-- .../src/chunked_array/ops/downcast.rs | 2 +- crates/polars-core/src/prelude.rs | 2 +- .../src/series/implementations/array.rs | 4 +- .../src/series/implementations/binary.rs | 4 +- .../series/implementations/binary_offset.rs | 4 +- .../src/series/implementations/boolean.rs | 4 +- .../src/series/implementations/categorical.rs | 4 +- .../src/series/implementations/dates_time.rs | 4 +- .../src/series/implementations/datetime.rs | 4 +- .../src/series/implementations/decimal.rs | 4 +- .../src/series/implementations/duration.rs | 4 +- .../src/series/implementations/floats.rs | 4 +- .../src/series/implementations/list.rs | 4 +- .../src/series/implementations/mod.rs | 4 +- .../src/series/implementations/null.rs | 2 +- .../src/series/implementations/object.rs | 4 +- .../src/series/implementations/string.rs | 4 +- .../src/series/implementations/struct_.rs | 2 +- crates/polars-core/src/series/series_trait.rs | 2 +- crates/polars-core/src/utils/mod.rs | 42 +++++++++---------- 21 files changed, 57 insertions(+), 57 deletions(-) diff --git a/crates/polars-core/src/chunked_array/mod.rs b/crates/polars-core/src/chunked_array/mod.rs index aad9a68ad2403..aa5b2abac007f 100644 --- a/crates/polars-core/src/chunked_array/mod.rs +++ b/crates/polars-core/src/chunked_array/mod.rs @@ -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, fn(&ArrayRef) -> usize>; +pub type ChunkLenIter<'a> = std::iter::Map, fn(&ArrayRef) -> usize>; /// # ChunkedArray /// @@ -359,8 +359,8 @@ impl ChunkedArray { 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()) } diff --git a/crates/polars-core/src/chunked_array/ops/downcast.rs b/crates/polars-core/src/chunked_array/ops/downcast.rs index 0abf87679cfe0..34246c1fd9edc 100644 --- a/crates/polars-core/src/chunked_array/ops/downcast.rs +++ b/crates/polars-core/src/chunked_array/ops/downcast.rs @@ -129,7 +129,7 @@ impl ChunkedArray { (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. diff --git a/crates/polars-core/src/prelude.rs b/crates/polars-core/src/prelude.rs index 3b43bb5a3ccae..eda6704d5c390 100644 --- a/crates/polars-core/src/prelude.rs +++ b/crates/polars-core/src/prelude.rs @@ -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; diff --git a/crates/polars-core/src/series/implementations/array.rs b/crates/polars-core/src/series/implementations/array.rs index 966a68b361b30..b8805389e016e 100644 --- a/crates/polars-core/src/series/implementations/array.rs +++ b/crates/polars-core/src/series/implementations/array.rs @@ -58,8 +58,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/binary.rs b/crates/polars-core/src/series/implementations/binary.rs index 8964ed83262f3..2229d49667773 100644 --- a/crates/polars-core/src/series/implementations/binary.rs +++ b/crates/polars-core/src/series/implementations/binary.rs @@ -98,8 +98,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/binary_offset.rs b/crates/polars-core/src/series/implementations/binary_offset.rs index 1a517782d8bd4..ab369a70aee8f 100644 --- a/crates/polars-core/src/series/implementations/binary_offset.rs +++ b/crates/polars-core/src/series/implementations/binary_offset.rs @@ -62,8 +62,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/boolean.rs b/crates/polars-core/src/series/implementations/boolean.rs index 938e74d56972c..13df1a2afaa90 100644 --- a/crates/polars-core/src/series/implementations/boolean.rs +++ b/crates/polars-core/src/series/implementations/boolean.rs @@ -120,8 +120,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/categorical.rs b/crates/polars-core/src/series/implementations/categorical.rs index cab3b9a8620c3..4d633a0f789b8 100644 --- a/crates/polars-core/src/series/implementations/categorical.rs +++ b/crates/polars-core/src/series/implementations/categorical.rs @@ -133,8 +133,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/dates_time.rs b/crates/polars-core/src/series/implementations/dates_time.rs index 9103542ad69dc..3becdf62fede2 100644 --- a/crates/polars-core/src/series/implementations/dates_time.rs +++ b/crates/polars-core/src/series/implementations/dates_time.rs @@ -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() diff --git a/crates/polars-core/src/series/implementations/datetime.rs b/crates/polars-core/src/series/implementations/datetime.rs index 15ada3f419104..f3d2f60220196 100644 --- a/crates/polars-core/src/series/implementations/datetime.rs +++ b/crates/polars-core/src/series/implementations/datetime.rs @@ -148,8 +148,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/decimal.rs b/crates/polars-core/src/series/implementations/decimal.rs index 678edabe45318..54a0ca144fbd0 100644 --- a/crates/polars-core/src/series/implementations/decimal.rs +++ b/crates/polars-core/src/series/implementations/decimal.rs @@ -175,8 +175,8 @@ impl SeriesTrait for SeriesWrap { 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 { diff --git a/crates/polars-core/src/series/implementations/duration.rs b/crates/polars-core/src/series/implementations/duration.rs index 7ba49d17ba95c..69b262ed3f1e3 100644 --- a/crates/polars-core/src/series/implementations/duration.rs +++ b/crates/polars-core/src/series/implementations/duration.rs @@ -208,8 +208,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/floats.rs b/crates/polars-core/src/series/implementations/floats.rs index 9817d15a04c92..228fe332ae222 100644 --- a/crates/polars-core/src/series/implementations/floats.rs +++ b/crates/polars-core/src/series/implementations/floats.rs @@ -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() diff --git a/crates/polars-core/src/series/implementations/list.rs b/crates/polars-core/src/series/implementations/list.rs index f5a02973ce50d..bf56441fe3346 100644 --- a/crates/polars-core/src/series/implementations/list.rs +++ b/crates/polars-core/src/series/implementations/list.rs @@ -54,8 +54,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/mod.rs b/crates/polars-core/src/series/implementations/mod.rs index abbdcbe192feb..2dcde908b8389 100644 --- a/crates/polars-core/src/series/implementations/mod.rs +++ b/crates/polars-core/src/series/implementations/mod.rs @@ -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() diff --git a/crates/polars-core/src/series/implementations/null.rs b/crates/polars-core/src/series/implementations/null.rs index bf4afebdc52bc..b1b06dd21aaa4 100644 --- a/crates/polars-core/src/series/implementations/null.rs +++ b/crates/polars-core/src/series/implementations/null.rs @@ -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()) } diff --git a/crates/polars-core/src/series/implementations/object.rs b/crates/polars-core/src/series/implementations/object.rs index 4255ace8098fa..8e59f9662e614 100644 --- a/crates/polars-core/src/series/implementations/object.rs +++ b/crates/polars-core/src/series/implementations/object.rs @@ -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 { diff --git a/crates/polars-core/src/series/implementations/string.rs b/crates/polars-core/src/series/implementations/string.rs index ce7a730267e9f..4532313af916c 100644 --- a/crates/polars-core/src/series/implementations/string.rs +++ b/crates/polars-core/src/series/implementations/string.rs @@ -99,8 +99,8 @@ impl SeriesTrait for SeriesWrap { 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() diff --git a/crates/polars-core/src/series/implementations/struct_.rs b/crates/polars-core/src/series/implementations/struct_.rs index 346b65491b141..a5b1d683d5d51 100644 --- a/crates/polars-core/src/series/implementations/struct_.rs +++ b/crates/polars-core/src/series/implementations/struct_.rs @@ -97,7 +97,7 @@ impl SeriesTrait for SeriesWrap { self.0.name() } - fn chunk_lengths(&self) -> ChunkIdIter { + fn chunk_lengths(&self) -> ChunkLenIter { let s = self.0.fields().first().unwrap(); s.chunk_lengths() } diff --git a/crates/polars-core/src/series/series_trait.rs b/crates/polars-core/src/series/series_trait.rs index e9dc8513073ba..cebfe9aa5df2c 100644 --- a/crates/polars-core/src/series/series_trait.rs +++ b/crates/polars-core/src/series/series_trait.rs @@ -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; diff --git a/crates/polars-core/src/utils/mod.rs b/crates/polars-core/src/utils/mod.rs index b3fb970707d58..c7f085d0dd336 100644 --- a/crates/polars-core/src/utils/mod.rs +++ b/crates/polars-core/src/utils/mod.rs @@ -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), ) }, @@ -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), ) }, @@ -786,32 +786,32 @@ 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), ) }, @@ -819,8 +819,8 @@ where 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())), ) }, _ => { @@ -828,8 +828,8 @@ where 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), ) }, @@ -1051,8 +1051,8 @@ mod test { b.append(&b2); let (a, b) = align_chunks_binary(&a, &b); assert_eq!( - a.chunk_id().collect::>(), - b.chunk_id().collect::>() + a.chunk_lengths().collect::>(), + b.chunk_lengths().collect::>() ); let a = Int32Chunked::new("", &[1, 2, 3, 4]); @@ -1063,8 +1063,8 @@ mod test { b.append(&b1); let (a, b) = align_chunks_binary(&a, &b); assert_eq!( - a.chunk_id().collect::>(), - b.chunk_id().collect::>() + a.chunk_lengths().collect::>(), + b.chunk_lengths().collect::>() ); } }