File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,32 @@ def df():
5050 return ctx .create_dataframe ([[batch ]])
5151
5252
53+ def test_named_struct (df ):
54+ df = df .with_column (
55+ "d" ,
56+ f .named_struct (
57+ literal ("a" ),
58+ column ("a" ),
59+ literal ("b" ),
60+ column ("b" ),
61+ literal ("c" ),
62+ column ("c" ),
63+ ),
64+ )
65+
66+ expected = """DataFrame()
67+ +-------+---+---------+------------------------------+
68+ | a | b | c | d |
69+ +-------+---+---------+------------------------------+
70+ | Hello | 4 | hello | {a: Hello, b: 4, c: hello } |
71+ | World | 5 | world | {a: World, b: 5, c: world } |
72+ | ! | 6 | ! | {a: !, b: 6, c: !} |
73+ +-------+---+---------+------------------------------+
74+ """ .strip ()
75+
76+ assert str (df ) == expected
77+
78+
5379def test_literal (df ):
5480 df = df .select (
5581 literal (1 ),
Original file line number Diff line number Diff line change @@ -503,6 +503,7 @@ expr_fn_vec!(trunc);
503503expr_fn ! ( upper, arg1, "Converts the string to all upper case." ) ;
504504expr_fn ! ( uuid) ;
505505expr_fn_vec ! ( r#struct) ; // Use raw identifier since struct is a keyword
506+ expr_fn_vec ! ( named_struct) ;
506507expr_fn ! ( from_unixtime, unixtime) ;
507508expr_fn ! ( arrow_typeof, arg_1) ;
508509expr_fn ! ( random) ;
@@ -680,6 +681,7 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
680681 m. add_wrapped ( wrap_pyfunction ! ( mean) ) ?;
681682 m. add_wrapped ( wrap_pyfunction ! ( median) ) ?;
682683 m. add_wrapped ( wrap_pyfunction ! ( min) ) ?;
684+ m. add_wrapped ( wrap_pyfunction ! ( named_struct) ) ?;
683685 m. add_wrapped ( wrap_pyfunction ! ( nanvl) ) ?;
684686 m. add_wrapped ( wrap_pyfunction ! ( now) ) ?;
685687 m. add_wrapped ( wrap_pyfunction ! ( nullif) ) ?;
You can’t perform that action at this time.
0 commit comments