diff --git a/crates/polars-core/src/chunked_array/array/mod.rs b/crates/polars-core/src/chunked_array/array/mod.rs index 15fe892d34045..41d39eb9df872 100644 --- a/crates/polars-core/src/chunked_array/array/mod.rs +++ b/crates/polars-core/src/chunked_array/array/mod.rs @@ -31,13 +31,14 @@ impl ArrayChunked { /// Get the inner values as `Series` pub fn get_inner(&self) -> Series { - let ca = self.rechunk(); let field = self.inner_dtype().to_arrow_field("item", true); - let arr = ca.downcast_iter().next().unwrap(); + let chunks: Vec<_> = self.downcast_iter().map(|c| c.values().clone()).collect(); + + // SAFETY: Data type of arrays matches because they are chunks from the same array. unsafe { Series::_try_from_arrow_unchecked_with_md( self.name(), - vec![(arr.values()).clone()], + chunks, &field.data_type, Some(&field.metadata), ) diff --git a/crates/polars-core/src/chunked_array/list/mod.rs b/crates/polars-core/src/chunked_array/list/mod.rs index eba65e8980ab4..4dc67f2564058 100644 --- a/crates/polars-core/src/chunked_array/list/mod.rs +++ b/crates/polars-core/src/chunked_array/list/mod.rs @@ -41,16 +41,18 @@ impl ListChunked { /// Get the inner values as [`Series`], ignoring the list offsets. pub fn get_inner(&self) -> Series { - let ca = self.rechunk(); - let arr = ca.downcast_iter().next().unwrap(); - // SAFETY: - // Inner dtype is passed correctly + let field = self.inner_dtype().to_arrow_field("item", true); + let chunks: Vec<_> = self.downcast_iter().map(|c| c.values().clone()).collect(); + + // SAFETY: Data type of arrays matches because they are chunks from the same array. unsafe { - Series::from_chunks_and_dtype_unchecked( + Series::_try_from_arrow_unchecked_with_md( self.name(), - vec![arr.values().clone()], - &ca.inner_dtype(), + chunks, + &field.data_type, + Some(&field.metadata), ) + .unwrap() } } diff --git a/py-polars/src/series/export.rs b/py-polars/src/series/export.rs index ef763e5c2adf7..4903b3df093e8 100644 --- a/py-polars/src/series/export.rs +++ b/py-polars/src/series/export.rs @@ -357,7 +357,7 @@ where /// Convert arrays by flattening first, converting the flat Series, and then reshaping. fn array_series_to_numpy(py: Python, s: &Series) -> PyObject { let ca = s.array().unwrap(); - let s_inner = ca.get_inner(); // TODO: This rechunks - is there a way to avoid this? + let s_inner = ca.get_inner(); let np_array_flat = series_to_numpy_with_copy(py, &s_inner).unwrap(); // Reshape to the original shape.