Skip to content

Commit

Permalink
BUG: groupby.transform retains timezone information (#25264)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and jreback committed Feb 16, 2019
1 parent 83fe6ca commit 9de4cc1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Bug Fixes

**Reshaping**

-
- Bug in :meth:`pandas.core.groupby.GroupBy.transform` where applying a function to a timezone aware column would return a timezone naive result (:issue:`24198`)
- Bug in :func:`DataFrame.join` when joining on a timezone aware :class:`DatetimeIndex` (:issue:`23931`)
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def _transform_fast(self, func, func_nm):

ids, _, ngroup = self.grouper.group_info
cast = self._transform_should_cast(func_nm)
out = algorithms.take_1d(func().values, ids)
out = algorithms.take_1d(func()._values, ids)
if cast:
out = self._try_cast(out, self.obj)
return Series(out, index=self.obj.index, name=self.obj.name)
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/groupby/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,14 @@ def demean_rename(x):
tm.assert_frame_equal(result, expected)
result_single = df.groupby('group').value.transform(demean_rename)
tm.assert_series_equal(result_single, expected['value'])


@pytest.mark.parametrize('func', [min, max, np.min, np.max, 'first', 'last'])
def test_groupby_transform_timezone_column(func):
# GH 24198
ts = pd.to_datetime('now', utc=True).tz_convert('Asia/Singapore')
result = pd.DataFrame({'end_time': [ts], 'id': [1]})
result['max_end_time'] = result.groupby('id').end_time.transform(func)
expected = pd.DataFrame([[ts, 1, ts]], columns=['end_time', 'id',
'max_end_time'])
tm.assert_frame_equal(result, expected)

0 comments on commit 9de4cc1

Please sign in to comment.