BUG: RollingGroupby when groupby key is in the index
State: closed

- [x] closes #37641
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Groupby
name: Window
description: rolling, ewma, expanding

Comments:
This will remove an index label in the case of partial overlap between the index labels and the groupby labels; I am wondering if a more natural behavior here would be "add any groupby labels to the index if they aren't already there".
Not sure if I 100% follow, but this is the resulting index behavior I am trying to mimic here:

```
In [1]: from pandas import *

In [2]:         arrays = [["val1", "val1", "val2"], ["val1", "val1", "val2"]]
   ...:         index = MultiIndex.from_arrays(arrays, names=("idx1", "idx2"))
   ...:
   ...:         df = DataFrame({"A": [1, 1, 2], "B": range(3)}, index=index)

In [3]: df
Out[3]:
           A  B
idx1 idx2
val1 val1  1  0
     val1  1  1
val2 val2  2  2

# idx2 is dropped
In [4]: df.groupby(["idx1", "A"]).mean()
Out[4]:
          B
idx1 A
val1 1  0.5
val2 2  2.0
```
Shouldn't `groupby(...).rolling` behave more like a transform than a reduction? In any case, the behavior here does not mimic a reduction in the case when the group labels are entirely not in the index (please correct me if this is wrong!). This means we are mimicking the behavior of a reduction in one case but not another.

I almost never use rolling in my work so I don't have much of an opinion as to what the right behavior is. Just noticed what I _think_ is an inconsistency.
Yes groupby.rolling should essentially act as a transform, and I think in both test cases I added the resulting shape (number of rows) is maintained with consideration that not all columns should be maintained since one of the columns was a grouping key.

```
In [7]:         arrays = [["val1", "val1", "val2"], ["val1", "val1", "val2"]]
   ...:         index = MultiIndex.from_arrays(arrays, names=("idx1", "idx2"))
   ...:
   ...:         df = DataFrame({"A": [1, 1, 2], "B": range(3)}, index=index)

In [8]: result = df.groupby(["idx1", "A"]).rolling(1).mean()

In [9]: result
Out[9]:
          B
idx1 A
val1 1  0.0
     1  1.0
val2 2  2.0

In [10]: df
Out[10]:
           A  B
idx1 idx2
val1 val1  1  0
     val1  1  1
val2 val2  2  2
```
thanks @mroeschke 
@meeseeksdev backport 1.1.x
Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

1. Checkout backport branch and update it.

```
$ git checkout 1.1.x
$ git pull
```

2. Cherry pick the first parent branch of the this PR on top of the older branch:
```
$ git cherry-pick -m1 87e554d8bad760b46103b07430b1be0dffec7ffc
```

3. You will likely have some merge/cherry-pick conflict here, fix them and commit:

```
$ git commit -am 'Backport PR #37661: BUG: RollingGroupby when groupby key is in the index'
```

4. Push to a named branch :

```
git push YOURFORK 1.1.x:auto-backport-of-pr-37661-on-1.1.x
```

5. Create a PR against branch 1.1.x, I would have named this PR:

> "Backport PR #37661 on branch 1.1.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).