I think this is what ``_groupby_indices`` does (a cython routine). also make an example that has an unsorted bins for testing as well.