Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jan 27, 2025
1 parent f2e024e commit f10ed21
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
5 changes: 1 addition & 4 deletions narwhals/_duckdb/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,16 +538,13 @@ def fill_null(self: Self, value: Any, strategy: Any, limit: int | None) -> Self:
)

def cast(self: Self, dtype: DType | type[DType]) -> Self:
def func(
_input: duckdb.Expression, dtype: DType | type[DType]
) -> duckdb.Expression:
def func(_input: duckdb.Expression) -> duckdb.Expression:
native_dtype = narwhals_to_native_dtype(dtype, self._version)
return _input.cast(native_dtype)

return self._from_call(
func,
"cast",
dtype=dtype,
returns_scalar=self._returns_scalar,
)

Expand Down
4 changes: 1 addition & 3 deletions narwhals/_duckdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import duckdb

from narwhals.dtypes import DType
from narwhals.utils import import_dtypes_module
from narwhals.utils import isinstance_or_issubclass

if TYPE_CHECKING:
from narwhals._duckdb.dataframe import DuckDBLazyFrame
from narwhals._duckdb.expr import DuckDBExpr
from narwhals.dtypes import DType
from narwhals.utils import Version


Expand All @@ -31,8 +31,6 @@ def maybe_evaluate(df: DuckDBLazyFrame, obj: Any) -> Any:
msg = "Reductions are not yet supported for DuckDB, at least until they implement duckdb.WindowExpression"
raise NotImplementedError(msg)
return column_result
if isinstance_or_issubclass(obj, DType):
return obj
return duckdb.ConstantExpression(obj)


Expand Down
4 changes: 1 addition & 3 deletions narwhals/_spark_like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pyspark.sql import types as pyspark_types
from pyspark.sql.window import Window

from narwhals.dtypes import DType
from narwhals.exceptions import UnsupportedDTypeError
from narwhals.utils import import_dtypes_module
from narwhals.utils import isinstance_or_issubclass
Expand All @@ -19,6 +18,7 @@

from narwhals._spark_like.dataframe import SparkLikeLazyFrame
from narwhals._spark_like.expr import SparkLikeExpr
from narwhals.dtypes import DType
from narwhals.utils import Version


Expand Down Expand Up @@ -145,8 +145,6 @@ def maybe_evaluate(df: SparkLikeLazyFrame, obj: Any) -> Any:
# Return scalar, let PySpark do its broadcasting
return column_result.over(Window.partitionBy(F.lit(1)))
return column_result
if isinstance_or_issubclass(obj, DType):
return obj
return F.lit(obj)


Expand Down

0 comments on commit f10ed21

Please sign in to comment.