Skip to content

Commit

Permalink
Remove a broken workaround I added, and replace it with actual fix fo…
Browse files Browse the repository at this point in the history
…r the problem.
  • Loading branch information
pythonspeed committed Sep 20, 2024
1 parent 0002d9a commit 9e2e346
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 1 addition & 8 deletions crates/polars-expr/src/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ pub struct CastExpr {

impl CastExpr {
fn finish(&self, input: &Series) -> PolarsResult<Series> {
let dtype = if input.dtype().is_list() && !self.dtype.is_nested() {
// Necessary for expressions that e.g. add UInt8 to List[Int64] to
// work.
&input.dtype().cast_leaf(self.dtype.clone())
} else {
&self.dtype
};
input.cast_with_options(dtype, self.options)
input.cast_with_options(&self.dtype, self.options)
}
}

Expand Down
14 changes: 8 additions & 6 deletions crates/polars-plan/src/plans/conversion/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ fn process_list_arithmetic(
expr_arena: &mut Arena<AExpr>,
) -> PolarsResult<Option<AExpr>> {
match (&type_left, &type_right) {
(DataType::List(inner), _) => {
if type_right != **inner {
(DataType::List(_), _) => {
let leaf = type_left.leaf_dtype();
if type_right != *leaf {
let new_node_right = expr_arena.add(AExpr::Cast {
expr: node_right,
dtype: *inner.clone(),
dtype: type_left.cast_leaf(leaf.clone()),
options: CastOptions::NonStrict,
});

Expand All @@ -73,11 +74,12 @@ fn process_list_arithmetic(
Ok(None)
}
},
(_, DataType::List(inner)) => {
if type_left != **inner {
(_, DataType::List(_)) => {
let leaf = type_right.leaf_dtype();
if type_left != *leaf {
let new_node_left = expr_arena.add(AExpr::Cast {
expr: node_left,
dtype: *inner.clone(),
dtype: type_right.cast_leaf(leaf.clone()),
options: CastOptions::NonStrict,
});

Expand Down

0 comments on commit 9e2e346

Please sign in to comment.