8000 fix: update arrow_cast function to accept string type for data_type p… · chenkovsky/datafusion-python@9e1ced7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e1ced7

Browse files
committed
fix: update arrow_cast function to accept string type for data_type parameter
1 parent dcaf0d6 commit 9e1ced7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

python/datafusion/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,9 @@ def arrow_typeof(arg: Expr) -> Expr:
11001100
return Expr(f.arrow_typeof(arg.expr))
11011101

11021102

1103-
def arrow_cast(expr: Expr, data_type: Expr) -> Expr:
1103+
def arrow_cast(expr: Expr, data_type: str) -> Expr:
11041104
"""Casts an expression to a specified data type."""
1105-
return Expr(f.arrow_cast(expr.expr, data_type.expr))
1105+
return Expr(f.arrow_cast(expr.expr, data_type))
11061106

11071107

11081108
def random() -> Expr:

src/functions.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ fn concat_ws(sep: String, args: Vec<PyExpr>) -> PyResult<PyExpr> {
144144
Ok(functions::string::expr_fn::concat_ws(lit(sep), args).into())
145145
}
146146

147+
/// Casts an expression to a specified data type.
148+
#[pyfunction]
149+
fn arrow_cast(expr: PyExpr, data_type: &str) -> PyResult<PyExpr> {
150+
Ok(functions::expr_fn::arrow_cast(expr.expr, data_type.to_string()).into())
151+
}
152+
147153
#[pyfunction]
148154
#[pyo3(signature = (values, regex, flags=None))]
149155
fn regexp_like(values: PyExpr, regex: PyExpr, flags: Option<PyExpr>) -> PyResult<PyExpr> {
@@ -563,7 +569,6 @@ expr_fn_vec!(r#struct); // Use raw identifier since struct is a keyword
563569
expr_fn_vec!(named_struct);
564570
expr_fn!(from_unixtime, unixtime);
565571
expr_fn!(arrow_typeof, arg_1);
566-
expr_fn!(arrow_cast, arg_1 datatype);
567572
expr_fn!(random);
568573

569574
// Array Functions

0 commit comments

Comments
 (0)
0