Skip to content

Commit

Permalink
fix: Proper dtype casting for struct embedded categoricals
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Sep 18, 2024
1 parent 25f84e4 commit 6208079
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/polars-core/src/datatypes/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ impl Display for DataType {
}

pub fn merge_dtypes(left: &DataType, right: &DataType) -> PolarsResult<DataType> {
// TODO! add struct
use DataType::*;
Ok(match (left, right) {
#[cfg(feature = "dtype-categorical")]
Expand Down Expand Up @@ -794,6 +793,15 @@ pub fn merge_dtypes(left: &DataType, right: &DataType) -> PolarsResult<DataType>
let merged = merge_dtypes(inner_l, inner_r)?;
List(Box::new(merged))
},
(Struct(inner_l), Struct(inner_r)) => {
polars_ensure!(inner_l.len() == inner_r.len(), ComputeError: "cannot combine different structs");
let fields = inner_l.iter().zip(inner_r.iter()).map(|(l, r)| {
polars_ensure!(l.name() == r.name(), ComputeError: "cannot combine different structs");
let merged = merge_dtypes(l.dtype(), r.dtype())?;
Ok(Field::new(l.name().clone(), merged))
}).collect::<PolarsResult<Vec<_>>>()?;
Struct(fields)
},
#[cfg(feature = "dtype-array")]
(Array(inner_l, width_l), Array(inner_r, width_r)) => {
polars_ensure!(width_l == width_r, ComputeError: "widths of FixedSizeWidth Series are not equal");
Expand Down

0 comments on commit 6208079

Please sign in to comment.