XGBRanker prediction

Hello, I am doing a ranking project and I use XGBRanker to train the training data (group parameter is passed in fit function), when I do prediction, I am confused since I saw in https://github.com/dmlc/xgboost/blob/master/demo/rank/rank_sklearn.py, you directly predict all test data (if I understand correctly, it assumes all test data in one group?) and I used the following way to do prediction:

def predict(model, df):
return model.predict(df.loc[:, ~df.columns.isin([‘id’])])

pred1 = (test_clean.groupby(‘id’)
.apply(lambda x: predict(model, x)))

I got a worse result compared with considering all test data as one group, can you explain why?