BUG: df.groupby().resample()[[cols]] without key columns raise KeyError
State: closed

- [x] closes #47362
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [x] Added an entry in the latest `doc/source/whatsnew/v1.5.0.rst` file if fixing a bug or adding a new feature.


Labels:
name: Groupby
name: Resample
description: resample method

Comments:
Hello @GYHHAHA! 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 2022-07-06 05:46:26 UTC
The reason why the current result only returns one column is `_cython_agg_general` blocks the non-numeric dtype when calling the `aggregate` from resample.
https://github.com/pandas-dev/pandas/blob/a9a496ce98285ee82f71fffa7cc503f122360d25/pandas/core/resample.py#L1266
https://github.com/pandas-dev/pandas/blob/a9a496ce98285ee82f71fffa7cc503f122360d25/pandas/core/groupby/groupby.py#L1662
I think we should allow the aggregation on datetime-like columns when corresponding key(s) is/are included, but this will change the current groupby behavior (and I'm not sure which one is desired). Also this may be related to #47177 , not clear about the logic.
```python
>>> df = pd.DataFrame(
    data={
        "date": pd.date_range(start="2016-01-01", periods=8),
        "group": [0, 0, 0, 0, 1, 1, 1, 1],
    }
)
>>> df.groupby("group")[["date", "group"]].mean()
# original
       group
group
0        0.0
1        1.0
# changed
                     date group
group
0     2016-01-02 12:00:00   0.0
1     2016-01-06 12:00:00   0.0
```
cc @mroeschke @rhshadrach 
I find a simple solution is keep the resample `exclusions` empty:
https://github.com/pandas-dev/pandas/blob/9612375ca28ade056f15d4338f1bfde5d045c9fc/pandas/core/resample.py#L169
But this fails the following test:
https://github.com/pandas-dev/pandas/blob/9612375ca28ade056f15d4338f1bfde5d045c9fc/pandas/tests/resample/test_resampler_grouper.py#L446
I personally think the test is not reasonable since we do want to get all the valid aggreation column results, thus the expect should have shape of (6, 4) instead of (6, 3). And as mentioned in the above pr, the default behavior will be changed in the future. A little confused. Discussion needed.
Since now we have DEPR the `numeric_only` on agg for resample and groupby, we should also DEPR the agg on groupby.resample agg function, which is currently not. And also the `numeric_only` keyword is still not work.
```python
>>>df=pd.DataFrame({"a":[0,0,1,1], "b":pd.date_range("20200101", "20200104")})
>>>df.groupby("a").resample("D", on="b")[["a", "b"]].mean()
# should DEPR but not
                a
a b
0 2020-01-01  0.0
  2020-01-02  0.0
1 2020-01-03  1.0
  2020-01-04  1.0
>>>df.groupby("a").resample("D", on="b")[["a", "b"]].mean(numeric_only=False)
# should include "b" column agg result but not
                a
a b
0 2020-01-01  0.0
  2020-01-02  0.0
1 2020-01-03  1.0
  2020-01-04  1.0
```
@GYHHAHA https://github.com/pandas-dev/pandas/pull/47605#issuecomment-1176785441 is fine to do but another PR
For the current BUG, I think the fix is enough. I can not add the test for `["val", "date"]` for this one since the result will be influenced by latter DEPR pr. @jreback 
Thanks @GYHHAHA