@@ -375,14 +375,17 @@ def sortColumnData(self, column):
375375 to group those variable types together.
376376 """
377377 # Prepare indices for variable types so we can group them together
378- order = [DiscreteVariable , ContinuousVariable , TimeVariable , StringVariable ]
378+ order = [ContinuousVariable , TimeVariable ,
379+ DiscreteVariable , StringVariable ]
379380 mapping = {var : idx for idx , var in enumerate (order )}
380381 vmapping = np .vectorize (mapping .__getitem__ )
381382 var_types_indices = vmapping (self ._variable_types )
382383
383384 # Store the variable name sorted indices so we can pass a default
384385 # order when sorting by multiple keys
385- var_name_indices = np .argsort (self ._variable_names )
386+ # Double argsort is "inverse" argsort:
387+ # data will be *sorted* by these indices
388+ var_name_indices = np .argsort (np .argsort (self ._variable_names ))
386389
387390 # Prepare vartype indices so ready when needed
388391 disc_idx , _ , time_idx , str_idx = self ._attr_indices (self .variables )
@@ -443,12 +446,21 @@ def _sortColumnData(self, column):
443446
444447 def _argsortData (self , data , order ):
445448 if data .ndim == 1 :
446- indices = np .argsort (data , kind = 'mergesort' )
447- if order == Qt .DescendingOrder :
448- indices = indices [::- 1 ]
449- # Always sort NaNs last
450449 if np .issubdtype (data .dtype , np .number ):
451- indices = np .roll (indices , - np .isnan (data ).sum ())
450+ if order == Qt .DescendingOrder :
451+ data = - data
452+ indices = np .argsort (data , kind = 'stable' )
453+ # Always sort NaNs last
454+ if np .issubdtype (data .dtype , np .number ):
455+ indices = np .roll (indices , - np .isnan (data ).sum ())
456+ else :
457+ # When not sorting by numbers, we can't do data = -data, but
458+ # use indices = indices[::-1] instead. This is not stable, but
459+ # doesn't matter because we use this only for variable names
460+ # which are guaranteed to be unique
461+ indices = np .argsort (data )
462+ if order == Qt .DescendingOrder :
463+ indices = indices [::- 1 ]
452464 else :
453465 assert np .issubdtype (data .dtype , np .number ), \
454466 'We do not deal with non numeric values in sorting by ' \
@@ -719,7 +731,7 @@ class Outputs:
719731 color_var = ContextSetting (None ) # type: Optional[Variable]
720732 # filter_string = ContextSetting('')
721733
722- sorting = Setting ((0 , Qt .DescendingOrder ))
734+ sorting = Setting ((0 , Qt .AscendingOrder ))
723735 selected_vars = ContextSetting ([], schema_only = True )
724736
725737 def __init__ (self ):
0 commit comments