From 2dbc6bf741fb8b6ccf123fb87bbc4a7c29e6c8b5 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Tue, 2 Aug 2022 17:36:13 +0200 Subject: [PATCH] convert arrow map to list (#4226) --- polars/polars-core/src/series/from.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/polars/polars-core/src/series/from.rs b/polars/polars-core/src/series/from.rs index e3ed83aa3120..452b526678bb 100644 --- a/polars/polars-core/src/series/from.rs +++ b/polars/polars-core/src/series/from.rs @@ -299,6 +299,33 @@ impl Series { Ok(s) } #[cfg(feature = "dtype-struct")] + ArrowDataType::Map(_field, _sorted) => { + let arr = if chunks.len() > 1 { + concatenate_owned_unchecked(&chunks).unwrap() as ArrayRef + } else { + chunks[0].clone() + }; + let arr = arr.as_any().downcast_ref::().unwrap(); + // inner type is a struct + let struct_array = arr.field().clone(); + + // small list, because that's the maps offset dtype. + // means we are limited to i32::MAX rows + let data_type = + ListArray::::default_datatype(struct_array.data_type().clone()); + // physical representation of the map + let new_arr = ListArray::new_unchecked( + data_type.clone(), + arr.offsets().clone(), + struct_array, + arr.validity().cloned(), + ); + let mut chunks = chunks; + chunks.clear(); + chunks.push(Box::new(new_arr)); + Self::try_from_arrow_unchecked(name, chunks, &data_type) + } + #[cfg(feature = "dtype-struct")] ArrowDataType::Struct(_) => { let arr = if chunks.len() > 1 { concatenate_owned_unchecked(&chunks).unwrap() as ArrayRef