@@ -202,6 +202,7 @@ def test_option_class_equality(request):
202202 pc .WeekOptions (week_starts_monday = True , count_from_zero = False ,
203203 first_week_is_fully_in_year = False ),
204204 pc .ZeroFillOptions (4 , "0" ),
205+ pc .InversePermutationOptions (- 1 , output_type = pa .int32 ()),
205206 ]
206207 # Timezone database might not be installed on Windows or Emscripten
207208 if request .config .pyarrow .is_enabled ["timezone_data" ]:
@@ -1590,6 +1591,45 @@ def test_filter_null_type():
15901591 assert len (table .filter (mask ).column (0 )) == 5
15911592
15921593
1594+ def test_inverse_permutation ():
1595+ arr0 = pa .array ([], type = pa .int32 ())
1596+ arr = pa .chunked_array ([
1597+ arr0 , [9 , 7 , 5 , 3 , 1 ], [0 ], [2 , 4 , 6 ], [8 ], arr0 ,
1598+ ])
1599+ result = pc .inverse_permutation (arr )
1600+ print (result )
1601+ expected = pa .chunked_array ([[5 , 4 , 6 , 3 , 7 , 2 , 8 , 1 , 9 , 0 ]], type = pa .int32 ())
1602+ assert result .equals (expected )
1603+
1604+ # `inverse_permutation` kernel currently does not accept options
1605+ options = pc .InversePermutationOptions (max_index = 4 , output_type = pa .int64 ())
1606+ print (options )
1607+ with pytest .raises (TypeError , match = "an unexpected keyword argument \' options\' " ):
1608+ pc .inverse_permutation (arr , options = options )
1609+
1610+ # `inverse_permutation` kernel currently won't accept max_index
1611+ with pytest .raises (TypeError , match = "an unexpected keyword argument \' max_index\' " ):
1612+ pc .inverse_permutation (arr , max_index = 4 )
1613+
1614+
1615+ def test_scatter ():
1616+ values = pa .array ([True , False , True , True , False , False , True , True , True , False ])
1617+ indices = pa .array ([9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ])
1618+ expected = pa .array ([False , True , True , True , False ,
1619+ False , True , True , False , True ])
1620+ result = pc .scatter (values , indices )
1621+ assert result .equals (expected )
1622+
1623+ # `scatter` kernel currently does not accept options
1624+ options = pc .ScatterOptions (max_index = 4 )
1625+ with pytest .raises (TypeError , match = "unexpected keyword argument \' options\' " ):
1626+ pc .scatter (values , indices , options = options )
1627+
1628+ # `scatter` kernel currently won't accept max_index
1629+ with pytest .raises (TypeError , match = "unexpected keyword argument \' max_index\' " ):
1630+ pc .scatter (values , indices , max_index = 4 )
1631+
1632+
15931633@pytest .mark .parametrize ("typ" , ["array" , "chunked_array" ])
15941634def test_compare_array (typ ):
15951635 if typ == "array" :
0 commit comments