Skip to content

Commit

Permalink
fix: Raise on invalid shape dataframe arithmetic (#17322)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Jul 1, 2024
1 parent ccdfbda commit 120ec7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-core/src/frame/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl DataFrame {
let df = if col_len < self.width() { self } else { other };

for i in col_len..max_len {
let s = &df.get_columns()[i];
let s = &df.get_columns().get(i).ok_or_else(|| polars_err!(InvalidOperation: "cannot do arithmetic on DataFrames with shapes: {:?} and {:?}", self.shape(), other.shape()))?;
let name = s.name();
let dtype = s.dtype();

Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/operations/arithmetic/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,8 @@ def test_date_datetime_sub() -> None:
"foo": [timedelta(days=-4)],
"bar": [timedelta(days=4)],
}


def test_raise_invalid_shape() -> None:
with pytest.raises(pl.exceptions.InvalidOperationError):
pl.DataFrame([[1, 2], [3, 4]]) * pl.DataFrame([1, 2, 3])

0 comments on commit 120ec7f

Please sign in to comment.