BUG: coercing of bools in groupby transform
State: closed

This bug is  happening because of the following lines of code(3054-3059 in groupby.py)
```      
       # we will only try to coerce the result type if
       # we have a numeric dtype, as these are *always* udfs
       # the cython take a different path (and casting)
       dtype = self._selected_obj.dtype
       if is_numeric_dtype(dtype):
           result = maybe_downcast_to_dtype(result, dtype)
```
the call to `maybe_downcast_to_dtype` successfully downcasts bool to float thus the result is 1.0.
I've put a guard in place to check if the result is boolean. This seems like an optimal solution, to me, since the behaviour of `maybe_downcast_to_dtype` seems consistent.

Fix inconsistency in groupby tranformations

 - [ ] closes #16875 
 - [ ] tests added / passed
 - [ ] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff`` (On Windows, ``git diff upstream/master -u -- "*.py" | flake8 --diff`` might work as an alternative.)
 - [ ] whatsnew entry


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

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

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

```diff
@@            Coverage Diff            @@
##             master   #16895   +/-   ##
=========================================
  Coverage          ?   90.99%           
=========================================
  Files             ?      161           
  Lines             ?    49288           
  Branches          ?        0           
=========================================
  Hits              ?    44848           
  Misses            ?     4440           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.76% <100%> (?)` | |
| #single | `40.2% <0%> (?)` | |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16895?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/cast.py](https://codecov.io/gh/pandas-dev/pandas/pull/16895?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Nhc3QucHk=) | `86.89% <100%> (ø)` | |

------

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

Hello @ikilledthecat! Thanks for updating the PR.







Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on July 16, 2017 at 01:12 Hours UTC
thanks!