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

Code before:
                    input,
                    options,
                })
            },
            #[cfg(all(feature = "range", feature = "dtype-date"))]
            AExpr::Function {
                function:
                    ref function @ IRFunctionExpr::Range(IRRangeFunction::DateRange {
                        interval: _,
                        closed: _,
                    })
                    | ref function @ IRFunctionExpr::Range(IRRangeFunction::DateRanges {
                        interval: _,
                        closed: _,
                    }),
                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 from_types = vec![type_start, type_end];
                let to_types = vec![DataType::Date, DataType::Date];

                // 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);
                }
            },
            #[cfg(all(feature = "range", feature = "dtype-datetime"))]
            AExpr::Function {
                function:

Review comment (refactor):
Could we remove this in favor of hardcoding `DataType::Date` in the loop below


Code after:
                    input,
                    options,
                })
            },
            #[cfg(all(feature = "range", feature = "dtype-date"))]
            AExpr::Function {
                function:
                    ref function @ IRFunctionExpr::Range(IRRangeFunction::DateRange {
                        interval: _,
                        closed: _,
                    })
                    | ref function @ IRFunctionExpr::Range(IRRangeFunction::DateRanges {
                        interval: _,
                        closed: _,
                    }),
                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 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 != DataType::Date {
                        modified = true;
                        coerce_temporal_dt(
                            &from_dtype,
                            &DataType::Date,
                            &mut input[i],
                            expr_arena,
                        )?;
                    }
                }

                if modified {
                    Some(AExpr::Function {
                        function,
                        input,
                        options,
                    })
                } else {
                    return Ok(None);
                }
            },