BUG: bug in sort for grouping with a categorical columns (GH8868)
Closes #8868

hack. I can add tests if this passes the CI and we think this should be taken further.

well you would need tests. Not sure this 'hack' is correct.
 @cottrell ok, other PR is merged in. Pls add tests and update. See if it can be done more naturally.
 @cottrell thanks

(this was correct)
