Skip to content

Commit

Permalink
fix(python): Raise ValueError on adding float to Series of dtype date (
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj authored Feb 5, 2023
1 parent b77265b commit 96490f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion py-polars/polars/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,5 +801,10 @@ def maybe_cast(

py_type = dtype_to_py_type(dtype)
if not isinstance(el, py_type):
el = py_type(el) # type: ignore[call-arg]
try:
el = py_type(el) # type: ignore[call-arg]
except Exception:
raise ValueError(
f"Cannot convert Python type {type(el)} to {dtype}"
) from None
return el
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_arithmetic(s: pl.Series) -> None:
2 % a
with pytest.raises(ValueError):
2**a
with pytest.raises(TypeError): # https://github.com/pola-rs/polars/issues/6617
with pytest.raises(ValueError):
+a
a = pl.Series("a", [""])
with pytest.raises(ValueError):
Expand Down

0 comments on commit 96490f2

Please sign in to comment.