diff --git a/crates/polars-arrow/src/legacy/kernels/string.rs b/crates/polars-arrow/src/legacy/kernels/string.rs index 4733605030ea..774cfab4860d 100644 --- a/crates/polars-arrow/src/legacy/kernels/string.rs +++ b/crates/polars-arrow/src/legacy/kernels/string.rs @@ -1,18 +1,18 @@ use crate::array::{Array, ArrayRef, UInt32Array, Utf8ViewArray}; use crate::buffer::Buffer; use crate::datatypes::ArrowDataType; -use crate::legacy::trusted_len::TrustedLenPush; pub fn utf8view_len_bytes(array: &Utf8ViewArray) -> ArrayRef { - let values = array.len_iter().collect::>(); - let values: Buffer<_> = values.into(); + let values: Buffer<_> = array.len_iter().collect(); let array = UInt32Array::new(ArrowDataType::UInt32, values, array.validity().cloned()); Box::new(array) } pub fn string_len_chars(array: &Utf8ViewArray) -> ArrayRef { - let values = array.values_iter().map(|x| x.chars().count() as u32); - let values: Buffer<_> = Vec::from_trusted_len_iter(values).into(); + let values: Buffer<_> = array + .values_iter() + .map(|x| x.chars().count() as u32) + .collect(); let array = UInt32Array::new(ArrowDataType::UInt32, values, array.validity().cloned()); Box::new(array) } diff --git a/crates/polars-core/src/frame/explode.rs b/crates/polars-core/src/frame/explode.rs index 8318fb1d10af..d3b28dd8b830 100644 --- a/crates/polars-core/src/frame/explode.rs +++ b/crates/polars-core/src/frame/explode.rs @@ -305,11 +305,9 @@ impl DataFrame { // values will all be placed in single column, so we must find their supertype let schema = self.schema(); - let mut iter = on.iter().map(|v| { - schema - .get(v) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", v)) - }); + let mut iter = on + .iter() + .map(|v| schema.get(v).ok_or_else(|| polars_err!(col_not_found = v))); let mut st = iter.next().unwrap()?.clone(); for dt in iter { st = try_get_supertype(&st, dt?)?; diff --git a/crates/polars-core/src/frame/mod.rs b/crates/polars-core/src/frame/mod.rs index a1216a9e5efc..45e110ba7fa1 100644 --- a/crates/polars-core/src/frame/mod.rs +++ b/crates/polars-core/src/frame/mod.rs @@ -189,7 +189,7 @@ impl DataFrame { /// Get the index of the column. fn check_name_to_idx(&self, name: &str) -> PolarsResult { self.get_column_index(name) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", name)) + .ok_or_else(|| polars_err!(col_not_found = name)) } fn check_already_present(&self, name: &str) -> PolarsResult<()> { @@ -1361,7 +1361,7 @@ impl DataFrame { /// Get column index of a [`Series`] by name. pub fn try_get_column_index(&self, name: &str) -> PolarsResult { self.get_column_index(name) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", name)) + .ok_or_else(|| polars_err!(col_not_found = name)) } /// Select a single column by name. @@ -1560,7 +1560,7 @@ impl DataFrame { .map(|name| { let idx = *name_to_idx .get(name.as_str()) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", name))?; + .ok_or_else(|| polars_err!(col_not_found = name))?; Ok(self .select_at_idx(idx) .unwrap() @@ -1588,7 +1588,7 @@ impl DataFrame { .map(|name| { let idx = *name_to_idx .get(name.as_str()) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", name))?; + .ok_or_else(|| polars_err!(col_not_found = name))?; Ok(self.select_at_idx(idx).unwrap().clone()) }) .collect::>>()? @@ -1696,7 +1696,7 @@ impl DataFrame { /// ``` pub fn rename(&mut self, column: &str, name: &str) -> PolarsResult<&mut Self> { self.select_mut(column) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", column)) + .ok_or_else(|| polars_err!(col_not_found = column)) .map(|s| s.rename(name))?; let unique_names: AHashSet<&str, ahash::RandomState> = AHashSet::from_iter(self.columns.iter().map(|s| s.name())); @@ -2968,7 +2968,7 @@ impl DataFrame { for col in cols { let _ = schema .get(&col) - .ok_or_else(|| polars_err!(ColumnNotFound: "{:?}", col))?; + .ok_or_else(|| polars_err!(col_not_found = col))?; } } DataFrame::new(new_cols) diff --git a/crates/polars-error/src/lib.rs b/crates/polars-error/src/lib.rs index 8c06452e3f89..720a6f3cdded 100644 --- a/crates/polars-error/src/lib.rs +++ b/crates/polars-error/src/lib.rs @@ -328,6 +328,9 @@ on startup."#.trim_start()) (duplicate = $name:expr) => { polars_err!(Duplicate: "column with name '{}' has more than one occurrences", $name) }; + (col_not_found = $name:expr) => { + polars_err!(ColumnNotFound: "{:?} not found", $name) + }; (oob = $idx:expr, $len:expr) => { polars_err!(OutOfBounds: "index {} is out of bounds for sequence of length {}", $idx, $len) };