Skip to content

Commit

Permalink
feat(rust, python): raise on both sides of datetime/str comparison (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and c-peters committed Jul 14, 2023
1 parent 38e237d commit 00c3cf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ pub(super) fn process_binary(
return Ok(None)
}
#[cfg(feature = "dtype-date")]
(Date, Utf8, op) if op.is_comparison() => err_date_str_compare()?,
(Date, Utf8, op) | (Utf8, Date, op) if op.is_comparison() => err_date_str_compare()?,
#[cfg(feature = "dtype-datetime")]
(Datetime(_, _), Utf8, op) if op.is_comparison() => err_date_str_compare()?,
(Datetime(_, _), Utf8, op) | (Utf8, Datetime(_, _), op) if op.is_comparison() => {
err_date_str_compare()?
}
#[cfg(feature = "dtype-time")]
(Time, Utf8, op) if op.is_comparison() => err_date_str_compare()?,
// structs can be arbitrarily nested, leave the complexity to the caller for now.
Expand Down
11 changes: 9 additions & 2 deletions py-polars/tests/unit/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,14 @@ def test_err_filter_no_expansion() -> None:
df.filter(pl.col(pl.Int16).min() < 0.1)


def test_date_string_comparison() -> None:
@pytest.mark.parametrize(
("e"),
[
pl.col("date") > "2021-11-10",
pl.col("date") < "2021-11-10",
],
)
def test_date_string_comparison(e: pl.Expr) -> None:
df = pl.DataFrame(
{
"date": [
Expand All @@ -439,7 +446,7 @@ def test_date_string_comparison() -> None:
with pytest.raises(
pl.ComputeError, match=r"cannot compare 'date/datetime/time' to a string value"
):
df.select(pl.col("date") > "2021-11-10")
df.select(e)


def test_err_on_multiple_column_expansion() -> None:
Expand Down

0 comments on commit 00c3cf6

Please sign in to comment.