BUG: fixed issue with mixed type groupby aggregate
State: closed

Fixes issue #16916, where using aggregate on a mixed type grouping
vector fails. Added test in test_aggregate.py to ensure that the bug
is fixed.

cc @ElDeveloper 

 - [x] closes #xxxx
 - [x] tests added / passed
 - [x] passes ``git diff upstream/master -u -- "*.py" | flake8 --diff``
 - [x] whatsnew entry


Labels:
name: Bug
name: Groupby
name: Dtype Conversions
description: Unexpected or buggy dtype conversions

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=h1) Report
> Merging [#17003](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7b9a57fc99fcd63c55b041ea7c76f5c390c12aa0?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/17003/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17003      +/-   ##
==========================================
+ Coverage   90.99%      91%   +<.01%     
==========================================
  Files         161      161              
  Lines       49291    49295       +4     
==========================================
+ Hits        44851    44859       +8     
+ Misses       4440     4436       -4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.77% <100%> (+0.02%)` | :arrow_up: |
| #single | `40.18% <0%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.08% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.76% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.33% <0%> (+0.09%)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.05% <0%> (+1.81%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17003?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/17003?src=pr&el=footer). Last update [7b9a57f...4c9e32d](https://codecov.io/gh/pandas-dev/pandas/pull/17003?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/17003?src=pr&el=h1) Report
> Merging [#17003](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/5279a172a86ac22250c5a382708e23917df79744?src=pr&el=desc) will **decrease** coverage by `0.22%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17003      +/-   ##
==========================================
- Coverage   91.25%   91.03%   -0.23%     
==========================================
  Files         163      161       -2     
  Lines       49810    49401     -409     
==========================================
- Hits        45456    44973     -483     
- Misses       4354     4428      +74
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.8% <100%> (-0.23%)` | :arrow_down: |
| #single | `40.28% <0%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.08% <100%> (-0.15%)` | :arrow_down: |
| [pandas/io/s3.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2lvL3MzLnB5) | `0% <0%> (-85%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/tools/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvZGF0ZXRpbWVzLnB5) | `66.94% <0%> (-18.31%)` | :arrow_down: |
| [pandas/util/\_decorators.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX2RlY29yYXRvcnMucHk=) | `65.65% <0%> (-12.35%)` | :arrow_down: |
| [pandas/core/dtypes/missing.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL21pc3NpbmcucHk=) | `87.19% <0%> (-3.26%)` | :arrow_down: |
| [pandas/core/indexes/accessors.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9hY2Nlc3NvcnMucHk=) | `88.09% <0%> (-1.27%)` | :arrow_down: |
| [pandas/core/reshape/pivot.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9waXZvdC5weQ==) | `95.2% <0%> (-1.16%)` | :arrow_down: |
| [pandas/io/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2lvL2NvbW1vbi5weQ==) | `67.79% <0%> (-0.85%)` | :arrow_down: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `90.58% <0%> (-0.61%)` | :arrow_down: |
| ... and [81 more](https://codecov.io/gh/pandas-dev/pandas/pull/17003?src=pr&el=tree-more) | |

------

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

@nreeve17 : Thanks for the PR!  I think you just need a `whatsnew` + some minor comments, and you should be all set!
I have re-added the bugfix line into the whatsnew doc, and I git pulled upstream master and pushed the changes with safe_sort.
looks like there is a ``TypeError`` raised somewhere which causes this to take an incorrect path.
@jreback, yeah, seems like the exception is coming from [this line](https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/src/inference.pyx#L363).
@jreback Is there anything you might suggest to fix this error? This error did not show up when we used the Try/Catch block
you have to pick out the cases where its failing and see exactly how it is failing. its possible ``safe_sort`` needs another case
can you rebase / update
Commits should be updated 👍 
can you rebase and update