BUG: use stable sort for group_index in groupby