Skip to content

Commit

Permalink
move_errors_to_lit_and_lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm0000 committed Apr 12, 2024
1 parent 7cb56ed commit 0ef5850
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 1 addition & 7 deletions py-polars/polars/_utils/parse_expr_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import polars._reexport as pl
from polars import functions as F
from polars._utils.deprecation import issue_deprecation_warning
from polars.exceptions import ComputeError, InvalidOperationError
from polars.exceptions import ComputeError

with contextlib.suppress(ImportError): # Module not available when building docs
import polars.polars as plr
Expand Down Expand Up @@ -121,12 +121,6 @@ def parse_as_expression(
elif isinstance(input, list) and not list_as_lit:
expr = F.lit(pl.Series(input), dtype=dtype)
structify = False
elif isinstance(input, pl.DataFrame):
msg = "A DataFrame is an invalid input"
raise InvalidOperationError(msg)
elif isinstance(input, pl.LazyFrame):
msg = "A LazyFrame is an invalid input"
raise InvalidOperationError(msg)
else:
expr = F.lit(input, dtype=dtype)
structify = False
Expand Down
10 changes: 8 additions & 2 deletions py-polars/polars/functions/lit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from polars.datatypes import Date, Datetime, Duration, Time
from polars.dependencies import _check_for_numpy
from polars.dependencies import numpy as np
from polars.exceptions import InvalidOperationError

with contextlib.suppress(ImportError): # Module not available when building docs
import polars.polars as plr
Expand Down Expand Up @@ -75,8 +76,13 @@ def lit(
>>> pl.lit(pl.Series("y", [[1, 2], [3, 4]])) # doctest: +IGNORE_RESULT
"""
time_unit: TimeUnit

if isinstance(value, datetime):
if isinstance(input, pl.DataFrame):
msg = "a DataFrame is an invalid input"
raise InvalidOperationError(msg)
elif isinstance(input, pl.LazyFrame):
msg = "a LazyFrame is an invalid input"
raise InvalidOperationError(msg)
elif isinstance(value, datetime):
if dtype is not None and (tu := getattr(dtype, "time_unit", "us")) is not None:
time_unit = tu # type: ignore[assignment]
else:
Expand Down

0 comments on commit 0ef5850

Please sign in to comment.