I was analyzing a Kaggle project and found below inconsistency:
We have a sales data for store (1, 2, 3) and items (1, 2, 3, 4, 5). The original author, wanted to calculate sum and mean for every combination of the store, item and period (month/year). and since s/he thought we should have visibility of only previous months when predicting the sales for current month, s/he decided to shift the sales vectors by 1. But this causes the issue that last month's Sales for store 1 product 1 becomes part of store 1 product 2.
data.groupby(["store", "item", "period"]).sales.agg(["sum", "mean"]).shift(1)
My initial thought was to maybe move shift operation after grouping but before aggregation.
data.groupby(["store", "item", "period"]).sales.shift(1).agg(["sum", "mean"])
Looking at outputs from the second line of code is very surprising for me. seems like aggregation didnt respect groupby indexation after shift was executed.
Screenshot showing code and output:

Has anybody experienced anything similar? is shifting really removes indexation from groupby operation?
EDIT:
adding the link to Original kaggle workbook: https://www.kaggle.com/ekrembayar/store-item-demand-forecasting-with-lgbm