@@ -358,43 +358,42 @@ def test_argsort(self, index):
358358 if isinstance (index , CategoricalIndex ):
359359 pytest .skip (f"{ type (self ).__name__ } separately tested" )
360360
361- # New test for mixed-int-string
362- if index .equals (Index ([0 , "a" , 1 , "b" , 2 , "c" ])):
363- result = index .astype (str ).argsort ()
364- expected = np .array (index .astype (str )).argsort ()
361+ # Handle non-MultiIndex object dtype indices
362+ if not isinstance (index , MultiIndex ) and index .dtype == "object" :
363+ str_index = index .astype (str )
364+ result = str_index .argsort ()
365+ expected = np .array (str_index ).argsort ()
365366 tm .assert_numpy_array_equal (result , expected , check_dtype = False )
366367 return
367368
369+ # Proceed with default logic for other indices
368370 result = index .argsort ()
369371 expected = np .array (index ).argsort ()
370372 tm .assert_numpy_array_equal (result , expected , check_dtype = False )
371373
372374 def test_numpy_argsort (self , index ):
373- # new test for mixed-int-string
374- if index .equals (Index ([0 , "a" , 1 , "b" , 2 , "c" ])):
375- result = np .argsort (index .astype (str ))
376- expected = index .astype (str ).argsort ()
375+ # Handle non-MultiIndex object dtype indices
376+ if not isinstance (index , MultiIndex ) and index .dtype == "object" :
377+ str_index = index .astype (str )
378+ result = np .argsort (str_index )
379+ expected = str_index .argsort ()
377380 tm .assert_numpy_array_equal (result , expected )
378381
379- result = np .argsort (index . astype ( str ) , kind = "mergesort" )
380- expected = index . astype ( str ) .argsort (kind = "mergesort" )
382+ result = np .argsort (str_index , kind = "mergesort" )
383+ expected = str_index .argsort (kind = "mergesort" )
381384 tm .assert_numpy_array_equal (result , expected )
382385 return
383386
387+ # Default logic for non-object dtype indices
384388 result = np .argsort (index )
385389 expected = index .argsort ()
386390 tm .assert_numpy_array_equal (result , expected )
387391
388392 result = np .argsort (index , kind = "mergesort" )
389393 expected = index .argsort (kind = "mergesort" )
390394 tm .assert_numpy_array_equal (result , expected )
391- # these are the only two types that perform
392- # pandas compatibility input validation - the
393- # rest already perform separate (or no) such
394- # validation via their 'values' attribute as
395- # defined in pandas.core.indexes/base.py - they
396- # cannot be changed at the moment due to
397- # backwards compatibility concerns
395+
396+ # Axis/order validation for specific index types
398397 if isinstance (index , (CategoricalIndex , RangeIndex )):
399398 msg = "the 'axis' parameter is not supported"
400399 with pytest .raises (ValueError , match = msg ):
0 commit comments