Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-core/src/frame/from.rs
6940 views
1
use crate::prelude::*;
2
3
impl TryFrom<StructArray> for DataFrame {
4
type Error = PolarsError;
5
6
fn try_from(arr: StructArray) -> PolarsResult<Self> {
7
let (fld, _length, arrs, nulls) = arr.into_data();
8
polars_ensure!(
9
nulls.is_none(),
10
ComputeError: "cannot deserialize struct with nulls into a DataFrame"
11
);
12
let columns = fld
13
.iter()
14
.zip(arrs)
15
.map(|(fld, arr)| {
16
// SAFETY:
17
// reported data type is correct
18
unsafe {
19
Series::_try_from_arrow_unchecked_with_md(
20
fld.name.clone(),
21
vec![arr],
22
fld.dtype(),
23
fld.metadata.as_deref(),
24
)
25
}
26
.map(Column::from)
27
})
28
.collect::<PolarsResult<Vec<_>>>()?;
29
DataFrame::new(columns)
30
}
31
}
32
33