-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: GH15429 transform result of timedelta from datetime #15430
BUG: GH15429 transform result of timedelta from datetime #15430
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
instead of this, use |
your bug report is the same as this: #10972 so please add these as tests cases. |
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -579,6 +579,8 @@ Bug Fixes | |||
|
|||
|
|||
|
|||
- Bug in ``groupby.transform`` where calculating a ``timedelta`` from a ``datetime`` caused a ``ValueError`` (:issue:`15429`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add 10972 as well (you can leave the other issue as well)
can you update |
4e790f6
to
e0004e7
Compare
I tried to use |
e0004e7
to
eb0f498
Compare
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -624,7 +624,8 @@ Bug Fixes | |||
- Bug in ``pd.concat()`` in which concatting with an empty dataframe with ``join='inner'`` was being improperly handled (:issue:`15328`) | |||
|
|||
|
|||
|
|||
- Bug in ``groupby.transform`` where calculating a ``timedelta`` from a ``datetime`` caused a ``ValueError`` (:issue:`15429`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do a single note with the issue number. make this simpler, something like: .transform incorrectly changing the dtype of the output.
pandas/core/groupby.py
Outdated
@@ -2906,8 +2906,15 @@ def transform(self, func, *args, **kwargs): | |||
common_type = np.common_type(np.array(res), result) | |||
if common_type != result.dtype: | |||
result = result.astype(common_type) | |||
except: | |||
pass | |||
except Exception as exc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh? this is way complicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this was a line I put into to see why the change to _find_common_type was causing problems.
@stephenrauch Which test broke when you used |
@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. |
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.
05d573e
to
c3b0dd0
Compare
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. closes pandas-dev#10972 Author: Jeff Reback <[email protected]> Author: Stephen Rauch <[email protected]> Closes pandas-dev#15430 from stephenrauch/group-by-transform-timedelta-from-datetime and squashes the following commits: c3b0dd0 [Jeff Reback] PEP fix 2f48549 [Jeff Reback] fixup slow transforms cc43503 [Stephen Rauch] BUG: GH15429 transform result of timedelta from datetime
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. closes pandas-dev#10972 Author: Jeff Reback <[email protected]> Author: Stephen Rauch <[email protected]> Closes pandas-dev#15430 from stephenrauch/group-by-transform-timedelta-from-datetime and squashes the following commits: c3b0dd0 [Jeff Reback] PEP fix 2f48549 [Jeff Reback] fixup slow transforms cc43503 [Stephen Rauch] BUG: GH15429 transform result of timedelta from datetime
thanks @stephenrauch I merged this (I actually needed some more fixes for making sure |
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. closes pandas-dev#10972 Author: Jeff Reback <[email protected]> Author: Stephen Rauch <[email protected]> Closes pandas-dev#15430 from stephenrauch/group-by-transform-timedelta-from-datetime and squashes the following commits: c3b0dd0 [Jeff Reback] PEP fix 2f48549 [Jeff Reback] fixup slow transforms cc43503 [Stephen Rauch] BUG: GH15429 transform result of timedelta from datetime
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.
git diff upstream/master | flake8 --diff