Skip to content
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
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
-<
8000
!-- -->0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,32 @@ def df():
50
50
return ctx .create_dataframe ([[batch ]])
51
51
52
52
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
+
53
79
def test_literal (df ):
54
80
df = df .select (
55
81
literal (1 ),
Original file line number Diff line number Diff line change @@ -503,6 +503,7 @@ expr_fn_vec!(trunc);
503
503
expr_fn ! ( upper, arg1, "Converts the string to all upper case." ) ;
504
504
expr_fn ! ( uuid) ;
505
505
expr_fn_vec ! ( r#struct) ; // Use raw identifier since struct is a keyword
506
+ expr_fn_vec ! ( named_struct) ;
506
507
expr_fn ! ( from_unixtime, unixtime) ;
507
508
expr_fn ! ( arrow_typeof, arg_1) ;
508
509
expr_fn ! ( random) ;
@@ -680,6 +681,7 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
680
681
m. add_wrapped ( wrap_pyfunction ! ( mean) ) ?;
681
682
m. add_wrapped ( wrap_pyfunction ! ( median) ) ?;
682
683
m. add_wrapped ( wrap_pyfunction ! ( min) ) ?;
684
+ m. add_wrapped ( wrap_pyfunction ! ( named_struct) ) ?;
683
685
m. add_wrapped ( wrap_pyfunction ! ( nanvl) ) ?;
684
686
m. add_wrapped ( wrap_pyfunction ! ( now) ) ?;
685
687
m. add_wrapped ( wrap_pyfunction ! ( nullif) ) ?;
You can’t perform that action at this time.
0 commit comments