Skip to content

Commit

Permalink
implicit datelike string comparison warning (#3967)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 10, 2022
1 parent 23e2762 commit 2d5be12
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions polars/polars-lazy/src/logical_plan/optimizer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ fn get_input(lp_arena: &Arena<ALogicalPlan>, lp_node: Node) -> [Option<Node>; 2]
inputs
}

fn print_date_str_comparison_warning() {
eprintln!("Warning: Comparing date/datetime/time column to string value, this will lead to string comparison and is unlikely what you want.\n\
If this is intended, consider using an explicit cast to silence this warning.")
}

impl OptimizationRule for TypeCoercionRule {
fn optimize_expr(
&self,
Expand Down Expand Up @@ -194,6 +199,18 @@ impl OptimizationRule for TypeCoercionRule {
{
return None
}
#[cfg(feature = "dtype-date")]
(DataType::Date, DataType::Utf8, op) if op.is_comparison() => {
print_date_str_comparison_warning()
}
#[cfg(feature = "dtype-datetime")]
(DataType::Datetime(_, _), DataType::Utf8, op) if op.is_comparison() => {
print_date_str_comparison_warning()
}
#[cfg(feature = "dtype-time")]
(DataType::Time, DataType::Utf8, op) if op.is_comparison() => {
print_date_str_comparison_warning()
}
_ => {}
}

Expand Down

0 comments on commit 2d5be12

Please sign in to comment.