@@ -44,8 +44,9 @@ def df():
44
44
datetime (2020 , 7 , 2 ),
45
45
]
46
46
),
47
+ pa .array ([False , True , True ]),
47
48
],
48
- names = ["a" , "b" , "c" , "d" ],
49
+ names = ["a" , "b" , "c" , "d" , "e" ],
49
50
)
50
51
return ctx .create_dataframe ([[batch ]])
51
52
@@ -63,15 +64,14 @@ def test_named_struct(df):
63
64
)
64
65
65
66
expected = """DataFrame()
66
- +-------+---+---------+------------------------------+
67
- | a | b | c | d |
68
- +-------+---+---------+------------------------------+
69
- | Hello | 4 | hello | {a: Hello, b: 4, c: hello } |
70
- | World | 5 | world | {a: World, b: 5, c: world } |
71
- | ! | 6 | ! | {a: !, b: 6, c: !} |
72
- +-------+---+---------+------------------------------+
67
+ +-------+---+---------+------------------------------+-------+
68
+ | a | b | c | d | e |
69
+ +-------+---+---------+------------------------------+-------+
70
+ | Hello | 4 | hello | {a: Hello, b: 4, c: hello } | false |
71
+ | World | 5 | world | {a: World, b: 5, c: world } | true |
72
+ | ! | 6 | ! | {a: !, b: 6, c: !} | true |
73
+ +-------+---+---------+------------------------------+-------+
73
74
""" .strip ()
74
-
75
75
assert str (df ) == expected
76
76
77
77
@@ -978,3 +978,22 @@ def test_binary_string_functions(df):
978
978
assert pa .array (result .column (1 )).cast (pa .string ()) == pa .array (
979
979
["Hello" , "World" , "!" ]
980
980
)
981
+
982
+
983
+ @pytest .mark .parametrize (
984
+ "python_datatype, name, expected" ,
985
+ [
986
+ pytest .param (bool , "e" , pa .bool_ (), id = "bool" ),
987
+ pytest .param (int , "b" , pa .int64 (), id = "int" ),
988
+ pytest .param (float , "b" , pa .float64 (), id = "float" ),
989
+ pytest .param (str , "b" , pa .string (), id = "str" ),
990
+ ],
991
+ )
992
+ def test_cast (df , python_datatype , name : str , expected ):
993
+ df = df .select (
994
+ column (name ).cast (python_datatype ).alias ("actual" ),
995
+ column (name ).cast (expected ).alias ("expected" ),
996
+ )
997
+ result = df .collect ()
998
+ result = result [0 ]
999
+ assert result .column (0 ) == result .column (1 )
0 commit comments