BUG: groupby with no non-empty groups, #21624
State: closed

Should close #21624. Didn't see any issues running test_fast.sh on my laptop so I don't think it broke anything in the process. The problem here is that when there is only a null group, then `self.result_index` is empty, but `ids` is just a list of -1s, so a ValueError is raised when trying to create the series. 

Labels:
name: Bug
name: Groupby

Comments:
tests!
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21849?src=pr&el=h1) Report
> Merging [#21849](https://codecov.io/gh/pandas-dev/pandas/pull/21849?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9d94a95c48b55f517569a00aafb3d378f05bd80f?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #21849      +/-   ##
==========================================
- Coverage   91.91%   91.91%   -0.01%     
==========================================
  Files         164      164              
  Lines       49987    49992       +5     
==========================================
+ Hits        45947    45951       +4     
- Misses       4040     4041       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.3% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.16% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21849?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/21849/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `96.35% <100%> (ø)` | :arrow_up: |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/21849/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `94.1% <0%> (-0.16%)` | :arrow_down: |
| [pandas/\_libs/tslibs/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/21849/diff?src=pr&el=tree#diff-cGFuZGFzL19saWJzL3RzbGlicy9fX2luaXRfXy5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/io/formats/style.py](https://codecov.io/gh/pandas-dev/pandas/pull/21849/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvc3R5bGUucHk=) | `96.16% <0%> (+0.03%)` | :arrow_up: |

------

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

Added in a test for this specific case. The other case where there are some but not all nans present is already covered extensively in the tests.
pls rebase, just reorged the groupby code a bit.
Should be ready for review now
I think nothing is breaking because this shouldn't be changing anything other than preventing a ValueError in an edge case. I think there is some ambiguity in the docs where we want to ignore NA values in group labels but also have transform return a series that's the same shape as the input. It would definitely be good to have the behavior of transform in the presence of NA group labels explicitly spelled out somewhere.
@jreback just tried locally and this wasn't working on master, so I think this change is still necessary
Closing as stale. Ping if you'd like to pick this back up