BUG: Fixes to FixedForwardWindowIndexer and GroupbyIndexer (#43267)
State: closed

- [x] closes https://github.com/pandas-dev/pandas/issues/43267

This PR addresses three issues, two major and one minor:

(1) If you repeated the use of a FixedForwardWindowIndexer, the indexer would be mutated and a window_size of 0 would be used.  This would lead to an empty end array which unsurprisingly led to segfaults on the second run.  Similar issues could be produced with other BaseIndexer subclasses, this one was simply the loudest.

(2) The end array generated by FixedForwardWindowIndexer.get_window_bounds was the wrong length, leading to longer arrays than necessary.  When there was only one involved, it didn't matter much: the extra ones were simply ignored.  But in the case of a groupby, these end arrays were concatenated, meaning that end values for the first group could leak into the second, and so on.

(3) There were some typos for "indices". 

Labels:
name: Groupby
name: Window
description: rolling, ewma, expanding
name: Segfault
description: Non-Recoverable Error

Comments:
@github-actions pre-commit

Hello @dsm054! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:













There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-10-16 18:44:59 UTC
@github-actions pre-commit
@dsm054 a few comments if you can update (and merge master)
I've booked time tomorrow to update to master and address outstanding comments.
@github-actions pre-commit
@jreback: what's the best way to teach mypy that something is (or can be taken to be) an int on a given code path?
> @jreback: what's the best way to teach mypy that something is (or can be taken to be) an int on a given code path?

can you point more specificiall, just `int` is fine (though its slightly tricky if we support also `np.integer` for this). if its in cython then mypy is not checking these.
@jreback: regarding the type problems, I'm talking about the mypy errors the build is preventing at the moment.  (So far, it's taken far longer to deal with the overhead of the process than it did to debug and fix the problem in the first place. :-)
@dsm054 

> (So far, it's taken far longer to deal with the overhead of the process than it did to debug and fix the problem in the first place. :-)

absolutely. code fixes are easy, tests hard, typing hard-est 
@dsm054 can you fixup / merge master when you can
@mroeschke 1.3.4 is scheduled for the end of the week. will you have time to push this over the line?

if not, would prefer not to push to 1.3.5, as it will hopefully be the last in 1.3.x and would require another 1.3.x release if any issues, so could either push to 1.4 or close as stale.
@simonjayhawkins I may be able to finish this on the weekend, so let's assume this will target 1.4
@mroeschke, @simonjayhawkins: thanks for picking this up!  (long story)
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.3.x
$ git pull
```

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

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

```
$ git commit -am 'Backport PR #43291: BUG: Fixes to FixedForwardWindowIndexer and GroupbyIndexer (#43267)'
```

4. Push to a named branch :

```
git push YOURFORK 1.3.x:auto-backport-of-pr-43291-on-1.3.x
```

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

> "Backport PR #43291 on branch 1.3.x (BUG: Fixes to FixedForwardWindowIndexer and GroupbyIndexer (#43267))"

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!

Remember to remove `Still Needs Manual Backport` label once the PR gets merged.

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