Skip to content

Commit d0a7273

Browse files
committed
feat: consolidate warning helpers and update temporal function calls
- Collapsed warning helpers into a single function `_warn_if_expr_for_literal_arg` in `python/datafusion/functions/__init__.py`. - Updated callers of temporal functions `_date_part` and `_date_trunc` in `python/datafusion/functions/__init__.py`. - Modified the digest behavior test in `python/tests/test_functions.py` to use native method strings. - Updated the encode/decode behavior test to use native "base64" in `python/tests/test_functions.py`.
1 parent 529f05d commit d0a7273

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

python/datafusion/functions/__init__.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,16 @@
6464
from datafusion.functions import spark
6565

6666

67-
def _warn_expr_for_literal_arg(function_name: str, arg_name: str) -> None:
68-
warnings.warn(
69-
f"Passing Expr for {function_name}() argument {arg_name!r} is deprecated; "
70-
"pass a Python literal instead.",
71-
DeprecationWarning,
72-
stacklevel=4,
73-
)
74-
75-
7667
def _warn_if_expr_for_literal_arg(
7768
value: Any, function_name: str, arg_name: str
7869
) -> None:
7970
if isinstance(value, Expr):
80-
_warn_expr_for_literal_arg(function_name, arg_name)
71+
warnings.warn(
72+
f"Passing Expr for {function_name}() argument {arg_name!r} is deprecated; "
73+
"pass a Python literal instead.",
74+
DeprecationWarning,
75+
stacklevel=3,
76+
)
8177

8278

8379
__all__ = [
@@ -2733,8 +2729,7 @@ def date_part(part: Expr | str, date: Expr) -> Expr:
27332729

27342730

27352731
def _date_part(part: Expr | str, date: Expr, function_name: str) -> Expr:
2736-
if isinstance(part, Expr):
2737-
_warn_expr_for_literal_arg(function_name, "part")
2732+
_warn_if_expr_for_literal_arg(part, function_name, "part")
27382733
part = coerce_to_expr(part)
27392734
return Expr(f.date_part(part.expr, date.expr))
27402735

@@ -2770,8 +2765,7 @@ def date_trunc(part: Expr | str, date: Expr) -> Expr:
27702765

27712766

27722767
def _date_trunc(part: Expr | str, date: Expr, function_name: str) -> Expr:
2773-
if isinstance(part, Expr):
2774-
_warn_expr_for_literal_arg(function_name, "part")
2768+
_warn_if_expr_for_literal_arg(part, function_name, "part")
27752769
part = coerce_to_expr(part)
27762770
return Expr(f.date_trunc(part.expr, date.expr))
27772771

python/tests/test_functions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ def test_string_functions(df, function, expected_result):
10141014

10151015
def test_hash_functions(df):
10161016
exprs = [
1017-
f.digest(column("a"), literal(m))
1017+
f.digest(column("a"), m)
10181018
for m in (
10191019
"md5",
10201020
"sha224",
@@ -1602,12 +1602,10 @@ def test_regr_funcs_df(func, expected):
16021602

16031603
def test_binary_string_functions(df):
16041604
df = df.select(
1605-
f.encode(column("a").cast(pa.string()), literal("base64").cast(pa.string())),
1605+
f.encode(column("a").cast(pa.string()), "base64"),
16061606
f.decode(
1607-
f.encode(
1608-
column("a").cast(pa.string()), literal("base64").cast(pa.string())
1609-
),
1610-
literal("base64").cast(pa.string()),
1607+
f.encode(column("a").cast(pa.string()), "base64"),
1608+
"base64",
16111609
),
16121610
)
16131611
result = df.collect()

0 commit comments

Comments
 (0)