Skip to content

Commit

Permalink
convert arrow map to list<struct> (#4226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 2, 2022
1 parent eb46056 commit 2dbc6bf
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions polars/polars-core/src/series/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MapArray>().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::<i32>::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
Expand Down

0 comments on commit 2dbc6bf

Please sign in to comment.