Skip to content

Commit

Permalink
error on invalid asof_join by input (#3053)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Apr 3, 2022
1 parent 6bb03b5 commit 1645f4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions polars/polars-core/src/frame/asof_join/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::fmt::Debug;
use std::hash::Hash;
use std::ops::Sub;

#[cfg(feature = "dtype-categorical")]
use crate::frame::hash_join::check_categorical_src;
use crate::frame::hash_join::{
create_probe_table, get_hash_tbl_threaded_join_partitioned, multiple_keys as mk, prepare_strs,
};
Expand Down Expand Up @@ -504,6 +506,11 @@ impl DataFrame {
}
}
} else {
for (lhs, rhs) in left_by.get_columns().iter().zip(right_by.get_columns()) {
check_asof_columns(lhs, rhs)?;
#[cfg(feature = "dtype-categorical")]
check_categorical_src(lhs.dtype(), rhs.dtype())?;
}
asof_join_by_multiple(&left_by, &right_by, left_asof, right_asof)
}
} else {
Expand Down
14 changes: 14 additions & 0 deletions py-polars/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ def test_error_on_reducing_map() -> None:
match="A 'map' functions output length must be equal to that of the input length. Consider using 'apply' in favor of 'map'.",
):
df.groupby("id").agg(pl.map(["t", "y"], np.trapz))


def test_error_on_invalid_by_in_asof_join() -> None:
df1 = pl.DataFrame(
{
"a": ["a", "b", "a"],
"b": [1, 2, 3],
"c": ["a", "b", "a"],
}
)

df2 = df1.with_column(pl.col("a").cast(pl.Categorical))
with pytest.raises(pl.ComputeError):
df1.join_asof(df2, on="b", by=["a", "c"])

0 comments on commit 1645f4a

Please sign in to comment.