BUG: GH15429 transform result of timedelta from datetime
State: closed

The transform() operation needs to return a like-indexed. To facilitate this, transform starts with a copy of the original series. Then, after the computation for each group, sets the appropriate elements of the copied series equal to the result. At that point is does a type comparison, and discovers that the timedelta is not cast-able to a datetime.

 - [x] closes #10972
 - [x] tests added / passed
 - [x] passes ``git diff upstream/master | 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/15430?src=pr&el=h1) Report
> Merging [#15430](https://codecov.io/gh/pandas-dev/pandas/pull/15430?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fb7dc7dcbde1d81dea28b1b83e1c3bd171a7e73d?src=pr&el=desc) will **decrease** coverage by `-0.01%`.
> The diff coverage is `100%`.


```diff
@@            Coverage Diff             @@
##           master   #15430      +/-   ##
==========================================
- Coverage   90.36%   90.36%   -0.01%     
==========================================
  Files         136      136              
  Lines       49553    49555       +2     
==========================================
+ Hits        44780    44781       +1     
- Misses       4773     4774       +1
```


| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/15430?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/compare/fb7dc7dcbde1d81dea28b1b83e1c3bd171a7e73d...c3b0dd086548156e14b5c97706bec63889461962?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `94.99% <100%> (ø)` | :white_check_mark: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/compare/fb7dc7dcbde1d81dea28b1b83e1c3bd171a7e73d...c3b0dd086548156e14b5c97706bec63889461962?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `81.91% <0%> (-0.19%)` | :x: |
| [pandas/types/cast.py](https://codecov.io/gh/pandas-dev/pandas/compare/fb7dc7dcbde1d81dea28b1b83e1c3bd171a7e73d...c3b0dd086548156e14b5c97706bec63889461962?src=pr&el=tree#diff-cGFuZGFzL3R5cGVzL2Nhc3QucHk=) | `85.65% <0%> (+0.23%)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/15430?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/15430?src=pr&el=footer). Last update [fb7dc7d...c3b0dd0](https://codecov.io/gh/pandas-dev/pandas/compare/fb7dc7dcbde1d81dea28b1b83e1c3bd171a7e73d...c3b0dd086548156e14b5c97706bec63889461962?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
instead of this, use ``pandas.type.cast._find_common_type`` rather than ``np.common_type``; that is some old code.
your bug report is the same as this: https://github.com/pandas-dev/pandas/issues/10972

so please add these as tests cases.
can you update
I tried to use `pandas.type.cast._find_common_type` rather than `np.common_type` in the function where this work was done, but one of the other test cases broke.  I looked at it, but didn't undertsand it well enough to know how to fix.
>  I looked at it, but didn't undertsand it well enough to know how to fix.

@stephenrauch Which test broke when you used `_find_common_type`? Can you try to describe the problem a bit more in detail? 
(also, if you add new commits to a PR instead of amending it to the first, it is easier to see what you changed and to comment on those steps)
@stephenrauch I have a fix for this which avoids all of this complication. I will push soon.
@stephenrauch ok (aside from a flake issue) I think this should work. But if you'd run the perf suite for groupby to see that wasn't changed too much. IIRC that's the reason we did the inplace indexing; and I think that was before we did the fast_transform anyhow (which is now a different path), so this maybe be ok.
thanks @stephenrauch I merged this (I actually needed some more fixes for making sure ``.agg`` didn't do the same thing). And perf testing was about the same.