BUG: use stable sort for group_index in groupby

Following on https://github.com/pydata/pandas/pull/8128, for certain `groupby` operations such as, 

    df.groupby(key)[col].transfrom('first')
it is necessary to use stable sort for group indices. As a result, `numpy.argsort` should be called with argument `kind='mergesort'`.