Skip to content

Commit

Permalink
fix: ensure nested logical types are converted to physical
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 9, 2023
1 parent 9d40f0a commit 5a0a023
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/polars-core/src/series/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ fn convert<F: Fn(&dyn Array) -> ArrayRef>(arr: &[ArrayRef], f: F) -> Vec<ArrayRe
}

/// Converts to physical types and bubbles up the correct [`DataType`].
fn to_physical_and_dtype(arrays: Vec<ArrayRef>) -> (Vec<ArrayRef>, DataType) {
unsafe fn to_physical_and_dtype(arrays: Vec<ArrayRef>) -> (Vec<ArrayRef>, DataType) {
match arrays[0].data_type() {
ArrowDataType::Utf8 => (
convert(&arrays, |arr| {
Expand Down Expand Up @@ -613,6 +613,19 @@ fn to_physical_and_dtype(arrays: Vec<ArrayRef>) -> (Vec<ArrayRef>, 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)
Expand Down

0 comments on commit 5a0a023

Please sign in to comment.