Skip to content

Commit

Permalink
Handle string unpacking failure
Browse files Browse the repository at this point in the history
  • Loading branch information
pentschev committed Nov 25, 2024
1 parent b7d2bf1 commit 9b54437
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion python/cudf_polars/cudf_polars/dsl/expressions/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class Name(IntEnum):
@classmethod
def from_polars(cls, obj: pl_expr.BooleanFunction) -> Self:
"""Convert from polars' `BooleanFunction`."""
function, name = str(obj).split(".", maxsplit=1)
try:
function, name = str(obj).split(".", maxsplit=1)
except ValueError:
# Failed to unpack string
function = None
if function != "BooleanFunction":
raise ValueError("BooleanFunction required")
return getattr(cls, name)
Expand Down
6 changes: 5 additions & 1 deletion python/cudf_polars/cudf_polars/dsl/expressions/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class Name(IntEnum):
@classmethod
def from_polars(cls, obj: pl_expr.TemporalFunction) -> Self:
"""Convert from polars' `TemporalFunction`."""
function, name = str(obj).split(".", maxsplit=1)
try:
function, name = str(obj).split(".", maxsplit=1)
except ValueError:
# Failed to unpack string
function = None
if function != "TemporalFunction":
raise ValueError("TemporalFunction required")
return getattr(cls, name)
Expand Down
6 changes: 5 additions & 1 deletion python/cudf_polars/cudf_polars/dsl/expressions/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ class Name(IntEnum):
@classmethod
def from_polars(cls, obj: pl_expr.StringFunction) -> Self:
"""Convert from polars' `StringFunction`."""
function, name = str(obj).split(".", maxsplit=1)
try:
function, name = str(obj).split(".", maxsplit=1)
except ValueError:
# Failed to unpack string
function = None
if function != "StringFunction":
raise ValueError("StringFunction required")
return getattr(cls, name)
Expand Down

0 comments on commit 9b54437

Please sign in to comment.