Skip to content

Commit

Permalink
fix(rust): bail on bool floordiv (#16578)
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite authored May 30, 2024
1 parent 3d655f0 commit 173ac1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/polars-ops/src/series/ops/floor_divide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub fn floor_div_series(a: &Series, b: &Series) -> PolarsResult<Series> {
_ => {},
}

if !a.dtype().is_numeric() {
polars_bail!(op = "floor_div", a.dtype());
}

let logical_type = a.dtype();

let a = a.to_physical_repr();
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/operations/arithmetic/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,13 @@ def test_null_column_arithmetic(op: Any) -> None:
# test broadcast left
output_df = df.select(op(pl.Series("a", [None]), pl.col("a")))
assert_frame_equal(expected_df, output_df)


def test_bool_floordiv() -> None:
df = pl.DataFrame({"x": [True]})

with pytest.raises(
pl.InvalidOperationError,
match="floor_div operation not supported for dtype `bool`",
):
df.with_columns(pl.col("x").floordiv(2))

0 comments on commit 173ac1c

Please sign in to comment.