From 8a29c08e35d3cfc86201934731245b2d4cf921f1 Mon Sep 17 00:00:00 2001 From: Philip Sampaio Date: Sun, 1 Dec 2024 19:04:42 -0300 Subject: [PATCH] Fix creation of struct series problem --- native/explorer/src/series/from_list.rs | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/native/explorer/src/series/from_list.rs b/native/explorer/src/series/from_list.rs index ec875914d..c0f48e135 100644 --- a/native/explorer/src/series/from_list.rs +++ b/native/explorer/src/series/from_list.rs @@ -440,25 +440,22 @@ pub fn s_from_list_of_series_as_structs( ex_dtype: ExSeriesDtype, ) -> NifResult { let dtype = DataType::try_from(&ex_dtype).unwrap(); - let series_vec = series_term.decode::>()?; - - StructChunked::from_series( - name.into(), - series_vec.len(), - // TODO: check if it's possible to avoid collexting here. - series_vec - .iter() - .map(|s| s.clone_inner()) - .collect::>() - .iter(), - ) - .map(|struct_chunked| struct_chunked.into_series()) - .and_then(|series| series.cast(&dtype)) - .map_err(|err| { - let message = format!("from_list/2 cannot create series of structs: {err:?}"); - Error::RaiseTerm(Box::new(message)) - }) - .map(ExSeries::new) + let columns = series_term + .decode::>()? + .into_iter() + .map(|c| Column::from(c.clone_inner())) + .collect(); + + let df = DataFrame::new(columns).unwrap(); + + df.into_struct(name.into()) + .into_series() + .cast(&dtype) + .map_err(|err| { + let message = format!("from_list/2 cannot create series of structs: {err:?}"); + Error::RaiseTerm(Box::new(message)) + }) + .map(ExSeries::new) } macro_rules! from_binary {