From 5a0a023050098687593934addde433d6a341479c Mon Sep 17 00:00:00 2001 From: ritchie Date: Mon, 9 Oct 2023 17:16:16 +0200 Subject: [PATCH] fix: ensure nested logical types are converted to physical --- crates/polars-core/src/series/from.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/polars-core/src/series/from.rs b/crates/polars-core/src/series/from.rs index 630666768d3f..5b639e309b26 100644 --- a/crates/polars-core/src/series/from.rs +++ b/crates/polars-core/src/series/from.rs @@ -489,7 +489,7 @@ fn convert ArrayRef>(arr: &[ArrayRef], f: F) -> Vec) -> (Vec, DataType) { +unsafe fn to_physical_and_dtype(arrays: Vec) -> (Vec, DataType) { match arrays[0].data_type() { ArrowDataType::Utf8 => ( convert(&arrays, |arr| { @@ -613,6 +613,19 @@ fn to_physical_and_dtype(arrays: Vec) -> (Vec, DataType) { (vec![arrow_array], DataType::Struct(polars_fields)) }) }, + // Use Series architecture to convert nested logical types to physical. + dt @ (ArrowDataType::Duration(_) + | ArrowDataType::Time32(_) + | ArrowDataType::Time64(_) + | ArrowDataType::Timestamp(_, _) + | ArrowDataType::Date32 + | ArrowDataType::Decimal(_, _) + | ArrowDataType::Date64) => { + let dt = dt.clone(); + let mut s = Series::_try_from_arrow_unchecked("", arrays, &dt).unwrap(); + let dtype = s.dtype().clone(); + (std::mem::take(s.chunks_mut()), dtype) + }, dt => { let dtype = dt.into(); (arrays, dtype)