Skip to content

Commit

Permalink
Dataframe editor: Make sorting stable; handle order correctly.
Browse files Browse the repository at this point in the history
- Set ascending flag correctly, fixes spyder-ide#3020.
- Use mergesort so that sorting is stable, fixes spyder-ide#3010.
- Use .sort_values() because .sort() is deprecated since pandas 0.17.
  • Loading branch information
jitseniesen committed Jun 21, 2016
1 parent c60c10a commit b6e996c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spyderlib/widgets/variableexplorer/dataframeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,20 @@ def sort(self, column, order=Qt.AscendingOrder):
"relation is defined for complex numbers")
return False
try:
ascending = order == Qt.AscendingOrder
if column > 0:
self.df.sort(columns=self.df.columns[column-1],
ascending=order, inplace=True)
try:
self.df.sort_values(by=self.df.columns[column-1],
ascending=ascending, inplace=True,
kind='mergesort')
except AttributeError:
# for pandas version < 0.17
self.df.sort(columns=self.df.columns[column-1],
ascending=ascending, inplace=True,
kind='mergesort')
self.update_df_index()
else:
self.df.sort_index(inplace=True, ascending=order)
self.df.sort_index(inplace=True, ascending=ascending)
self.update_df_index()
except TypeError as e:
QMessageBox.critical(self.dialog, "Error",
Expand Down

0 comments on commit b6e996c

Please sign in to comment.