From 28e7fc716a0e43166bc1304347bdd6bdd6d5aff5 Mon Sep 17 00:00:00 2001 From: Niko Date: Mon, 7 Oct 2024 14:35:49 +0200 Subject: [PATCH] Allow fill_null to be used with torch tensors --- py-polars/polars/functions/lit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/functions/lit.py b/py-polars/polars/functions/lit.py index 98e4cc6d6b23..4070a6e39dc4 100644 --- a/py-polars/polars/functions/lit.py +++ b/py-polars/polars/functions/lit.py @@ -158,7 +158,7 @@ def lit( if dtype: return wrap_expr(plr.lit(value, allow_object, is_scalar=True)).cast(dtype) - try: + if isinstance(value, np.generic): # numpy literals like np.float32(0) have item/dtype item = value.item() @@ -176,7 +176,7 @@ def lit( time_unit = dtype_name[len("timedelta64[") : -1] return lit(item).cast(Duration(time_unit)) - except AttributeError: + else: item = value return wrap_expr(plr.lit(item, allow_object, is_scalar=True))