Skip to content

Commit eba0d32

Browse files
committed
fix: update arrow_cast function to accept string type for data_type parameter
1 parent b80ae94 commit eba0d32

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

python/datafusion/functions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"""User functions for operating on :py:class:`~datafusion.expr.Expr`."""
1818

1919
from __future__ import annotations
20-
2120
from datafusion._internal import functions as f
2221
from datafusion.expr import (
2322
CaseBuilder,
@@ -1100,9 +1099,9 @@ def arrow_typeof(arg: Expr) -> Expr:
11001099
return Expr(f.arrow_typeof(arg.expr))
11011100

11021101

1103-
def arrow_cast(expr: Expr, data_type: Expr) -> Expr:
1102+
def arrow_cast(expr: Expr, data_type: str) -> Expr:
11041103
"""Casts an expression to a specified data type."""
1105-
return Expr(f.arrow_cast(expr.expr, data_type.expr))
1104+
return Expr(f.arrow_cast(expr.expr, literal(data_type).expr))
11061105

11071106

11081107
def random() -> Expr:

python/tests/test_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ def test_temporal_functions(df):
907907

908908
def test_arrow_cast(df):
909909
df = df.select(
910-
f.arrow_cast(column("a"), literal("Float64")).alias("a_as_float"),
911-
f.arrow_cast(column("a"), literal("Int32")).alias("a_as_int"),
910+
f.arrow_cast(column("a"), "Float64").alias("a_as_float"),
911+
f.arrow_cast(column("a"), "Int32").alias("a_as_int"),
912912
)
913913
result = df.collect()
914914
assert len(result) == 1

0 commit comments

Comments
 (0)