Repository: pola-rs/polars
File: crates/polars-plan/src/plans/conversion/type_coercion/mod.rs (Rust)

Code before:
            AExpr::Function {
                function:
                    ref function @ IRFunctionExpr::Range(IRRangeFunction::DatetimeRange {
                        ref interval,
                        closed: _,
                        time_unit: ref tu,
                        time_zone: ref tz,
                    })
                    | ref function @ IRFunctionExpr::Range(IRRangeFunction::DatetimeRanges {
                        ref interval,
                        closed: _,
                        time_unit: ref tu,
                        time_zone: ref tz,
                    }),
                ref input,
                options,
            } => {
                let mut input = input.clone();
                let function = function.clone();

                // Determine the current and target dtypes.
                let type_start = try_get_dtype(expr_arena, input[0].node(), schema)?;
                let type_end = try_get_dtype(expr_arena, input[1].node(), schema)?;
                let default = try_get_supertype(&type_start, &type_end)?;
                let supertype = temporal_range_output_type(default, tu, tz, interval)?;
                let from_types = vec![type_start, type_end];
                let to_types = vec![supertype.clone(), supertype];

                // Upcast input expressions if necessary.
                let from_iter = from_types.into_iter();
                let to_iter = to_types.into_iter();
                let mut modified = false;
                for (i, (from_dtype, to_dtype)) in from_iter.zip(to_iter).enumerate() {
                    if from_dtype != to_dtype {
                        modified = true;
                        coerce_temporal_dt(&from_dtype, &to_dtype, &mut input[i], expr_arena)?;
                    }
                }

                if modified {
                    Some(AExpr::Function {
                        function,
                        input,
                        options,
                    })
                } else {
                    return Ok(None);
                }
            },
            AExpr::Slice { offset, length, .. } => {
                let (_, offset_dtype) = unpack!(get_aexpr_and_type(expr_arena, offset, schema));

Review comment (suggestion):
```suggestion
                let from_types = [type_start, type_end];
```

Code after:
                }
            },
            #[cfg(all(feature = "range", feature = "dtype-datetime"))]
            AExpr::Function {
                function:
                    ref function @ IRFunctionExpr::Range(IRRangeFunction::DatetimeRange {
                        ref interval,
                        closed: _,
                        time_unit: ref tu,
                        time_zone: ref tz,
                    })
                    | ref function @ IRFunctionExpr::Range(IRRangeFunction::DatetimeRanges {
                        ref interval,
                        closed: _,
                        time_unit: ref tu,
                        time_zone: ref tz,
                    }),
                ref input,
                options,
            } => {
                let mut input = input.clone();
                let function = function.clone();

                // Determine the current and target dtypes.
                let type_start = try_get_dtype(expr_arena, input[0].node(), schema)?;
                let type_end = try_get_dtype(expr_arena, input[1].node(), schema)?;
                let default = try_get_supertype(&type_start, &type_end)?;
                let supertype = temporal_range_output_type(default, tu, tz, interval)?;
                let from_types = [type_start, type_end];

                // Upcast input expressions if necessary.
                let from_iter = from_types.into_iter();
                let mut modified = false;
                for (i, from_dtype) in from_iter.enumerate() {
                    if from_dtype != supertype {
                        modified = true;
                        coerce_temporal_dt(&from_dtype, &supertype, &mut input[i], expr_arena)?;
                    }
                }

                if modified {
                    Some(AExpr::Function {
                        function,
                        input,
                        options,
                    })
                } else {
                    return Ok(None);
                }
            },
            AExpr::Slice { offset, length, .. } => {