TestPeriodIndex.test_resample_empty_dataframe is failed when I pass kwargs to Resampler._groupby_and_aggregate
State: closed

- [x] closes #22339
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

`test_resample.py::TestPeriodIndex::test_resample_empty_dataframe` triggers new changes


Labels:
name: Bug
name: Resample
description: resample method

Comments:
@jreback 

I investigated `test_resample.py::TestPeriodIndex::test_resample_empty_dataframe` test and found that `Grouby.var` may fail when `ddof = 1`. Other methods have `_python_agg_general` in case of exception, so I added the same behaviour for `var`.

Let me know if it's acceptable solution.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=h1) Report
> Merging [#22364](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/2a2d1cfb00d69e92192eeca8e11488f782f25337?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22364/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22364      +/-   ##
==========================================
+ Coverage   92.05%   92.05%   +<.01%     
==========================================
  Files         169      169              
  Lines       50709    50714       +5     
==========================================
+ Hits        46679    46684       +5     
  Misses       4030     4030
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.46% <100%> (ø)` | :arrow_up: |
| #single | `42.25% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/resample.py](https://codecov.io/gh/pandas-dev/pandas/pull/22364/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzYW1wbGUucHk=) | `96.08% <100%> (ø)` | :arrow_up: |
| [pandas/core/groupby/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/22364/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9ncm91cGJ5LnB5) | `96.18% <100%> (+0.02%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=footer). Last update [2a2d1cf...793adcc](https://codecov.io/gh/pandas-dev/pandas/pull/22364?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@WillAyd 

After adding `kwargs` to `_groupby_and_aggregate`, changes are triggered  this test `test_resample.py::TestPeriodIndex::test_resample_empty_dataframe`.
Hmm not sure I completely follow - was this test failing before? 
@WillAyd 

> Hmm not sure I completely follow - was this test failing before?

This test is failed using following changes.

```
diff --git a/pandas/core/resample.py b/pandas/core/resample.py
index 4a3625b2d..c82382f96 100644
--- a/pandas/core/resample.py
+++ b/pandas/core/resample.py
@@ -1043,7 +1043,7 @@ class PeriodIndexResampler(DatetimeIndexResampler):

         if is_subperiod(ax.freq, self.freq):
             # Downsampling
-            return self._groupby_and_aggregate(how, grouper=self.grouper)
+            return self._groupby_and_aggregate(how, grouper=self.grouper, **kwargs)
         elif is_superperiod(ax.freq, self.freq):
             if how == 'ohlc':
                 # GH #13083
@@ -1051,7 +1051,7 @@ class PeriodIndexResampler(DatetimeIndexResampler):
                 # for pure aggregating/reducing methods
                 # OHLC reduces along the time dimension, but creates multiple
                 # values for each period -> handle by _groupby_and_aggregate()
-                return self._groupby_and_aggregate(how, grouper=self.grouper)
+                return self._groupby_and_aggregate(how, grouper=self.grouper, **kwargs)
             return self.asfreq()
         elif ax.freq == self.freq:
             return self.asfreq()
```
How is this visible from the end user perspective? The test case you provided works fine on master so asserting that it continues to work doesn't measure much. 

However this is visible to an end user you should set up a test case to cover that
@WillAyd

Just wanted to make sure that we are on the same page. @jreback suggested to create a new issue for this case [here](https://github.com/pandas-dev/pandas/pull/22304#discussion_r209901909). So, I created #22339 and this PR to close my original PR #22304, it's my goal at the moment.

I can make all changes within PR #22304 if it looks fine to you.




A separate PR is fine. Whatever you were planning to xfail in the other PR should be included as a test here
@WillAyd 

There is already test that covers new changes: `TestPeriodIndex.test_resample_empty_dataframe`. I can create a separate test for `var`, for instance: `test_resample_empty_dataframe_var` which would duplicate the logic from `test_resample_empty_dataframe`. Are you okay with this approach?
follow up ^. It would be more explicit
Will fix within https://github.com/pandas-dev/pandas/pull/22304

see [here](https://github.com/pandas-dev/pandas/pull/22304#discussion_r210545908)