GroupKFold inconsistent under ties in group sizes.

### Describe the bug

Due to the use of argsort (a non stable sort withthout the stable parameter introduced in numpy 2.0), GroupKFold is not always reproducible when there are ties in group sizes.

### Steps/Code to Reproduce

You may need to run this on different machines, but you can reproduce this issue with even less code than GroupKFold by simply testing `np.argsort`.
```
import numpy as np

x = np.array([0.37454012, 0.95071431, 0.73199394, 0.        , 0.15601864,
       0.        , 0.05808361, 0.86617615, 0.60111501, 0.70807258,
       0.02058449, 0.96990985, 0.83244264, 0.21233911, 0.18182497,
       0.18340451, 0.30424224, 0.52475643, 0.43194502, 0.29122914,
       0.61185289, 0.13949386, 0.29214465, 0.36636184, 0.45606998,
       0.78517596, 0.19967378, 0.51423444, 0.59241457, 0.        ,
       0.60754485, 0.17052412, 0.06505159, 0.        , 0.96563203,
       0.80839735, 0.        , 0.        , 0.68423303, 0.44015249,
       0.12203823])

print(np.argsort(x))
```
Both times with numpy version: 1.26.4
machine a: `array(3,5,29,33,36,37,10,6,32,40...`
machine b: `array(37,36,3,29,5,33,10,6,32,40...`

### Expected Results

Technically a stable sort isn't required, no need to maintain the original ordering. However a consistent sort result is required for reproducibility.  Stable sort is an easy way to achieve this that is already built into numpy.

### Actual Results

Both times with numpy version: 1.26.4
machine a: `array(3,5,29,33,36,37,10,6,32,40...`
machine b: `array(37,36,3,29,5,33,10,6,32,40...`

### Versions

```shell
sklearn versions are mostly irrelevant here as the issue is with calling a numpy method that requires additional changes.
```

COMMENT:
The following example gives different results on 2 different machines both with the same version of numpy listed above and scikit-learn 1.5.1, adapted from your example, as your example gives the same results on both:
```
import numpy as np
from numpy.testing import assert_array_equal
from sklearn.model_selection import GroupKFold

def test_group_k_fold_reproducible():
    groups = np.repeat(np.arange(41), 5)
    X = np.arange(41*5)
    gkf = GroupKFold(2)
    first_split = [a for a in gkf.split(X, groups=groups)]
    second_split = [a for a in gkf.split(X, groups=groups)]
    for (train1, test1), (train2, test2) in zip(first_split, second_split):
        print(train1) # this is the line that matters
```

If you run this on separate machines, you _may_ get different results. For example on 2 machines I got the following results:

a.
```
[10 11 12 13 14 20 21 22 23 24 30 31 32 33 34 40 41 42 43 44 50 51 52 53 54 60 61 62 63 64 70 71 72 73 74 80 81 82 83 84 90 91 92 93 94 95 96 97 98 99 110 111 112 113 114 120 121 122 123 124 130 131 132 133 134 140 141 142 143 144 150 151 152 153 154 160 161 162 163 164 170 171 172 173 174 180 181 182 183 184 190 191 192 193 194 195 196 197 198 199]

[0 1 2 3 4 5 6 7 8 9 15 16 17 18 19 25 26 27 28 29 35 36 37 38 39 45 46 47 48 49 55 56 57 58 59 65 66 67 68 69 75 76 77 78 79 85 86 87 88 89 100 101 102 103 104 105 106 107 108 109 115 116 117 118 119 125 126 127 128 129 135 136 137 138 139 145 146 147 148 149 155 156 157 158 159 165 166 167 168 169 175 176 177 178 179 185 186 187 188 189 200 201 202 203 204]
```

b.
```
[5 6 7 8 9 15 16 17 18 19 25 26 27 28 29 35 36 37 38 39 45 46 47 48 49 55 56 57 58 59 65 66 67 68 69 75 76 77 78 79 85 86 87 88 89 95 96 97 98 99 105 106 107 108 109 115 116 117 118 119 125 126 127 128 129 135 136 137 138 139 145 146 147 148 149 155 156 157 158 159 165 166 167 168 169 175 176 177 178 179 185 186 187 188 189 195 196 197 198 199]
[0 1 2 3 4 10 11 12 13 14 20 21 22 23 24 30 31 32 33 34 40 41 42 43 44 50 51 52 53 54 60 61 62 63 64 70 71 72 73 74 80 81 82 83 84 90 91 92 93 94 100 101 102 103 104 110 111 112 113 114 120 121 122 123 124 130 131 132 133 134 140 141 142 143 144 150 151 152 153 154 160 161 162 163 164 170 171 172 173 174 180 181 182 183 184 190 191 192 193 194 200 201 202 203 204]
```
Immediately from this, you can see that in the first run 0-4 are in the same group as 5-9 but in the second run they are in separate groups, so it isn't just an issue of order of records in the groups but also an issue of group assignment.

I'm not sure of a way to ge this issue on the same machine, though I don't know enough about the numpy implementation to rule that out I guess.

Labels: Bug