@@ -2975,6 +2975,32 @@ def test_table_group_by_first():
2975
2975
assert result .equals (expected )
2976
2976
2977
2977
2978
+ @pytest .mark .acero
2979
+ def test_table_group_by_pivot_wider ():
2980
+ table = pa .table ({'group' : [1 , 2 , 3 , 1 , 2 , 3 ],
2981
+ 'key' : ['h' , 'h' , 'h' , 'w' , 'w' , 'w' ],
2982
+ 'value' : [10 , 20 , 30 , 40 , 50 , 60 ]})
2983
+
2984
+ with pytest .raises (ValueError , match = 'accepts 3 arguments but 2 passed' ):
2985
+ table .group_by ("group" ).aggregate ([("key" , "pivot_wider" )])
2986
+
2987
+ # GH-45739: calling hash_pivot_wider without options shouldn't crash
2988
+ # (even though it's not very useful as key_names=[])
2989
+ result = table .group_by ("group" ).aggregate ([(("key" , "value" ), "pivot_wider" )])
2990
+ expected = pa .table ({'group' : [1 , 2 , 3 ],
2991
+ 'key_value_pivot_wider' : [{}, {}, {}]})
2992
+ assert result .equals (expected )
2993
+
2994
+ options = pc .PivotWiderOptions (key_names = ('h' , 'w' ))
2995
+ result = table .group_by ("group" ).aggregate (
2996
+ [(("key" , "value" ), "pivot_wider" , options )])
2997
+ expected = pa .table (
2998
+ {'group' : [1 , 2 , 3 ],
2999
+ 'key_value_pivot_wider' : [
3000
+ {'h' : 10 , 'w' : 40 }, {'h' : 20 , 'w' : 50 }, {'h' : 30 , 'w' : 60 }]})
3001
+ assert result .equals (expected )
3002
+
3003
+
2978
3004
def test_table_to_recordbatchreader ():
2979
3005
table = pa .Table .from_pydict ({'x' : [1 , 2 , 3 ]})
2980
3006
reader = table .to_reader ()
0 commit comments