ENH: Exclude nuisance columns from result of window functions
State: closed

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


Labels:
name: Enhancement
name: Dtype Conversions
description: Unexpected or buggy dtype conversions
name: Window
description: rolling, ewma, expanding

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=h1) Report
> Merging [#27044](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/b4aa1d66ecc8d391e8003a0a398bd96fe956bfdf?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `61.29%`.

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

```diff
@@            Coverage Diff             @@
##           master   #27044      +/-   ##
==========================================
- Coverage      92%   91.99%   -0.02%     
==========================================
  Files         180      180              
  Lines       50754    50774      +20     
==========================================
+ Hits        46698    46708      +10     
- Misses       4056     4066      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.63% <61.29%> (-0.01%)` | :arrow_down: |
| #single | `41.81% <3.22%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/window.py](https://codecov.io/gh/pandas-dev/pandas/pull/27044/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvd2luZG93LnB5) | `96.01% <61.29%> (-0.63%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/27044/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `88.88% <0%> (-11.12%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/27044/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.89% <0%> (-0.12%)` | :arrow_down: |
| [pandas/compat/\_optional.py](https://codecov.io/gh/pandas-dev/pandas/pull/27044/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fb3B0aW9uYWwucHk=) | `100% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27044?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/27044?src=pr&el=footer). Last update [b4aa1d6...035a697](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@8b48f5c`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `65.51%`.

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

```diff
@@            Coverage Diff            @@
##             master   #27044   +/-   ##
=========================================
  Coverage          ?   92.03%           
=========================================
  Files             ?      180           
  Lines             ?    50735           
  Branches          ?        0           
=========================================
  Hits              ?    46692           
  Misses            ?     4043           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.67% <65.51%> (?)` | |
| #single | `41.86% <6.89%> (?)` | |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/window.py](https://codecov.io/gh/pandas-dev/pandas/pull/27044/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvd2luZG93LnB5) | `96.23% <65.51%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27044?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/27044?src=pr&el=footer). Last update [8b48f5c...fd678a5](https://codecov.io/gh/pandas-dev/pandas/pull/27044?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

How does this interact with https://github.com/pandas-dev/pandas/issues/23002, which would like to apply (certain) operations to non-numeric columns?
@WillAyd DataError seems reasonable. I just checked how `DataFrame` functions behave and it led me to returning an empty `Series` like:
```python
>>> pd.DataFrame({"A": ['foo']}).mean()
Series([], dtype: float64)
```

@TomAugspurger this doesn't resolves it. Instead of an error an empty `Series` will be returned (as a result of using `Rolling.apply` with a string column) but it seems to be wrong as mentioned
Not sure why some test on py35_macos are failing. Will try to reproduce it
this looks good. can you merge master and ping on green.
@WillAyd if any other comments.
@ihsansecer see the failure https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=13461

I *think* this might be an ordering issue (as the dict is not ordered on 3.5).
lgtm. @TomAugspurger @jorisvandenbossche if any comments.
Thanks @ihsansecer !