From 570eafdf2f2431f37b32bf077c5e6fbc9c41ad6e Mon Sep 17 00:00:00 2001 From: coastalwhite Date: Tue, 3 Dec 2024 15:15:27 +0100 Subject: [PATCH] chore: Remove useless SeriesTrait::get implementations --- .../polars-core/src/series/implementations/array.rs | 4 ---- .../polars-core/src/series/implementations/binary.rs | 4 ---- .../src/series/implementations/binary_offset.rs | 4 ---- .../polars-core/src/series/implementations/boolean.rs | 4 ---- .../src/series/implementations/categorical.rs | 4 ---- crates/polars-core/src/series/implementations/date.rs | 4 ---- .../src/series/implementations/datetime.rs | 4 ---- .../polars-core/src/series/implementations/decimal.rs | 4 ---- .../src/series/implementations/duration.rs | 4 ---- .../polars-core/src/series/implementations/floats.rs | 4 ---- crates/polars-core/src/series/implementations/list.rs | 4 ---- crates/polars-core/src/series/implementations/mod.rs | 4 ---- crates/polars-core/src/series/implementations/null.rs | 5 ----- .../polars-core/src/series/implementations/string.rs | 4 ---- .../polars-core/src/series/implementations/struct_.rs | 4 ---- crates/polars-core/src/series/implementations/time.rs | 4 ---- crates/polars-core/src/series/series_trait.rs | 11 +++++++---- 17 files changed, 7 insertions(+), 69 deletions(-) diff --git a/crates/polars-core/src/series/implementations/array.rs b/crates/polars-core/src/series/implementations/array.rs index 51bd084cd46d..b1929167b515 100644 --- a/crates/polars-core/src/series/implementations/array.rs +++ b/crates/polars-core/src/series/implementations/array.rs @@ -145,10 +145,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/binary.rs b/crates/polars-core/src/series/implementations/binary.rs index b0fe79845a0d..fac7a5086c5d 100644 --- a/crates/polars-core/src/series/implementations/binary.rs +++ b/crates/polars-core/src/series/implementations/binary.rs @@ -174,10 +174,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/binary_offset.rs b/crates/polars-core/src/series/implementations/binary_offset.rs index 481b5c5bf47e..07844d96a994 100644 --- a/crates/polars-core/src/series/implementations/binary_offset.rs +++ b/crates/polars-core/src/series/implementations/binary_offset.rs @@ -146,10 +146,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/boolean.rs b/crates/polars-core/src/series/implementations/boolean.rs index b4cd48295c4c..2c8becc2edab 100644 --- a/crates/polars-core/src/series/implementations/boolean.rs +++ b/crates/polars-core/src/series/implementations/boolean.rs @@ -208,10 +208,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/categorical.rs b/crates/polars-core/src/series/implementations/categorical.rs index 7c45baa5c054..00a32d0dea83 100644 --- a/crates/polars-core/src/series/implementations/categorical.rs +++ b/crates/polars-core/src/series/implementations/categorical.rs @@ -223,10 +223,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/date.rs b/crates/polars-core/src/series/implementations/date.rs index a2ef6ed0788c..8aa8c43f608a 100644 --- a/crates/polars-core/src/series/implementations/date.rs +++ b/crates/polars-core/src/series/implementations/date.rs @@ -266,10 +266,6 @@ impl SeriesTrait for SeriesWrap { } } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/datetime.rs b/crates/polars-core/src/series/implementations/datetime.rs index 7f0d575bd916..109275dbcd34 100644 --- a/crates/polars-core/src/series/implementations/datetime.rs +++ b/crates/polars-core/src/series/implementations/datetime.rs @@ -260,10 +260,6 @@ impl SeriesTrait for SeriesWrap { } } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/decimal.rs b/crates/polars-core/src/series/implementations/decimal.rs index 612505057eca..bd4049efb42f 100644 --- a/crates/polars-core/src/series/implementations/decimal.rs +++ b/crates/polars-core/src/series/implementations/decimal.rs @@ -294,10 +294,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, cast_options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/duration.rs b/crates/polars-core/src/series/implementations/duration.rs index 803ca813aa1c..555e630ac3fb 100644 --- a/crates/polars-core/src/series/implementations/duration.rs +++ b/crates/polars-core/src/series/implementations/duration.rs @@ -380,10 +380,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, cast_options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/floats.rs b/crates/polars-core/src/series/implementations/floats.rs index 85c0d87cf0f1..780f8130ed72 100644 --- a/crates/polars-core/src/series/implementations/floats.rs +++ b/crates/polars-core/src/series/implementations/floats.rs @@ -254,10 +254,6 @@ macro_rules! impl_dyn_series { self.0.cast_with_options(dtype, cast_options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/list.rs b/crates/polars-core/src/series/implementations/list.rs index 5e5b4a95d5e2..529a5f9e98d5 100644 --- a/crates/polars-core/src/series/implementations/list.rs +++ b/crates/polars-core/src/series/implementations/list.rs @@ -148,10 +148,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, cast_options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/mod.rs b/crates/polars-core/src/series/implementations/mod.rs index d4b9626d2bfc..fb1a093f130d 100644 --- a/crates/polars-core/src/series/implementations/mod.rs +++ b/crates/polars-core/src/series/implementations/mod.rs @@ -326,10 +326,6 @@ macro_rules! impl_dyn_series { self.0.cast_with_options(dtype, options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/null.rs b/crates/polars-core/src/series/implementations/null.rs index 72b4e14114eb..ea4f903375fa 100644 --- a/crates/polars-core/src/series/implementations/null.rs +++ b/crates/polars-core/src/series/implementations/null.rs @@ -222,11 +222,6 @@ impl SeriesTrait for NullChunked { NullChunked::new(self.name.clone(), length).into_series() } - fn get(&self, index: usize) -> PolarsResult { - polars_ensure!(index < self.len(), oob = index, self.len()); - Ok(AnyValue::Null) - } - unsafe fn get_unchecked(&self, _index: usize) -> AnyValue { AnyValue::Null } diff --git a/crates/polars-core/src/series/implementations/string.rs b/crates/polars-core/src/series/implementations/string.rs index 2547d9bd237c..1d68298681a5 100644 --- a/crates/polars-core/src/series/implementations/string.rs +++ b/crates/polars-core/src/series/implementations/string.rs @@ -179,10 +179,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, cast_options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/implementations/struct_.rs b/crates/polars-core/src/series/implementations/struct_.rs index d40e53d1a01e..d9e75399a988 100644 --- a/crates/polars-core/src/series/implementations/struct_.rs +++ b/crates/polars-core/src/series/implementations/struct_.rs @@ -150,10 +150,6 @@ impl SeriesTrait for SeriesWrap { self.0.cast_with_options(dtype, cast_options) } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) } diff --git a/crates/polars-core/src/series/implementations/time.rs b/crates/polars-core/src/series/implementations/time.rs index 870efc27de7e..99696c8e84d6 100644 --- a/crates/polars-core/src/series/implementations/time.rs +++ b/crates/polars-core/src/series/implementations/time.rs @@ -228,10 +228,6 @@ impl SeriesTrait for SeriesWrap { } } - fn get(&self, index: usize) -> PolarsResult { - self.0.get_any_value(index) - } - #[inline] unsafe fn get_unchecked(&self, index: usize) -> AnyValue { self.0.get_any_value_unchecked(index) diff --git a/crates/polars-core/src/series/series_trait.rs b/crates/polars-core/src/series/series_trait.rs index c77a9de0f7ad..ed420ec0d0b1 100644 --- a/crates/polars-core/src/series/series_trait.rs +++ b/crates/polars-core/src/series/series_trait.rs @@ -398,7 +398,12 @@ pub trait SeriesTrait: /// Get a single value by index. Don't use this operation for loops as a runtime cast is /// needed for every iteration. - fn get(&self, _index: usize) -> PolarsResult; + fn get(&self, index: usize) -> PolarsResult { + polars_ensure!(index < self.len(), oob = index, self.len()); + // SAFETY: Just did bounds check + let value = unsafe { self.get_unchecked(index) }; + Ok(value) + } /// Get a single value by index. Don't use this operation for loops as a runtime cast is /// needed for every iteration. @@ -407,9 +412,7 @@ pub trait SeriesTrait: /// /// # Safety /// Does not do any bounds checking - unsafe fn get_unchecked(&self, _index: usize) -> AnyValue { - invalid_operation_panic!(get_unchecked, self) - } + unsafe fn get_unchecked(&self, _index: usize) -> AnyValue; fn sort_with(&self, _options: SortOptions) -> PolarsResult { polars_bail!(opq = sort_with, self._dtype());