diff --git a/crates/polars-core/src/chunked_array/ops/any_value.rs b/crates/polars-core/src/chunked_array/ops/any_value.rs index f492e3fee9a1..fa5f913c5f5d 100644 --- a/crates/polars-core/src/chunked_array/ops/any_value.rs +++ b/crates/polars-core/src/chunked_array/ops/any_value.rs @@ -187,12 +187,12 @@ macro_rules! get_any_value_unchecked { macro_rules! get_any_value { ($self:ident, $index:expr) => {{ - let (chunk_idx, idx) = $self.index_to_chunked_index($index); - let arr = &*$self.chunks[chunk_idx]; - polars_ensure!(idx < arr.len(), oob = idx, arr.len()); + if $index >= $self.len() { + polars_bail!(oob = $index, $self.len()); + } // SAFETY // bounds are checked - Ok(unsafe { arr_to_any_value(arr, idx, $self.dtype()) }) + Ok(unsafe { $self.get_any_value_unchecked($index) }) }}; } diff --git a/crates/polars-core/src/chunked_array/ops/downcast.rs b/crates/polars-core/src/chunked_array/ops/downcast.rs index d31ee0b545f4..fc1fad4aae03 100644 --- a/crates/polars-core/src/chunked_array/ops/downcast.rs +++ b/crates/polars-core/src/chunked_array/ops/downcast.rs @@ -99,7 +99,13 @@ impl ChunkedArray { #[inline] pub(crate) fn index_to_chunked_index(&self, index: usize) -> (usize, usize) { if self.chunks.len() == 1 { - return (0, index); + // SAFETY: chunks.len() == 1 guarantees this is correct. + let len = unsafe { self.chunks.get_unchecked(0).len() }; + return if index < len { + (0, index) + } else { + (1, index - len) + }; } index_to_chunked_index(self.downcast_iter().map(|arr| arr.len()), index) } diff --git a/crates/polars-ops/src/chunked_array/strings/concat.rs b/crates/polars-ops/src/chunked_array/strings/concat.rs index feb0026b9f0e..781e1da2175c 100644 --- a/crates/polars-ops/src/chunked_array/strings/concat.rs +++ b/crates/polars-ops/src/chunked_array/strings/concat.rs @@ -65,11 +65,6 @@ pub fn hor_str_concat(cas: &[&Utf8Chunked], delimiter: &str) -> PolarsResult