Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust, python): raise more informative error on string arguments #9352

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions polars/polars-core/src/frame/asof_join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub struct AsOfOptions {
fn check_asof_columns(a: &Series, b: &Series, check_sorted: bool) -> PolarsResult<()> {
let dtype_a = a.dtype();
let dtype_b = b.dtype();
polars_ensure!(
dtype_a.to_physical().is_numeric() && dtype_b.to_physical().is_numeric(),
InvalidOperation:
"asof join only supported on numeric/temporal keys"
);
polars_ensure!(
dtype_a == dtype_b,
ComputeError: "mismatching key dtypes in asof-join: `{}` and `{}`",
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/operations/test_join_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any

import numpy as np
import pytest

import polars as pl
from polars.testing import assert_frame_equal
Expand Down Expand Up @@ -486,3 +487,12 @@ def test_asof_join_nearest_by_date() -> None:

out = df1.join_asof(df2, on="asof_key", by="group", strategy="nearest")
assert_frame_equal(out, expected)


def test_asof_join_string_err() -> None:
left = pl.DataFrame({"date_str": ["2023/02/15"]}).sort("date_str")
right = pl.DataFrame(
{"date_str": ["2023/01/31", "2023/02/28"], "value": [0, 1]}
).sort("date_str")
with pytest.raises(pl.InvalidOperationError):
left.join_asof(right, on="date_str")