File tree 3 files changed +15
-2
lines changed
3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -578,6 +578,7 @@ Bug Fixes
578
578
579
579
- Bug in ``DataFrame.to_stata()`` and ``StataWriter`` which produces incorrectly formatted files to be produced for some locales (:issue:`13856`)
580
580
- Bug in ``pd.concat()`` in which concatting with an empty dataframe with ``join='inner'`` was being improperly handled (:issue:`15328`)
581
+ - Bug in ``groupby.agg()`` incorrectly localizing timezone on ``datetime`` (:issue:`15426`)
581
582
582
583
583
584
Original file line number Diff line number Diff line change 6
6
"""
7
7
8
8
from __future__ import print_function
9
- from datetime import datetime
9
+ from datetime import datetime , timedelta
10
10
from functools import partial
11
11
12
12
import numpy as np
@@ -738,3 +738,14 @@ def test_agg_over_numpy_arrays(self):
738
738
columns = expected_column )
739
739
740
740
assert_frame_equal (result , expected )
741
+
742
+ def test_agg_time_zone_round_trip (self ):
743
+ ts = pd .Timestamp ("2016-01-01 12:00:00" , tz = 'US/Pacific' )
744
+ df = pd .DataFrame ({'a' : 1 , 'b' : [ts + timedelta (minutes = nn )
745
+ for nn in range (10 )]})
746
+
747
+ result1 = df .groupby ('a' )['b' ].agg (np .min ).iloc [0 ]
748
+ result2 = df .groupby ('a' )['b' ].agg (lambda x : np .min (x )).iloc [0 ]
749
+
750
+ self .assertEqual (result1 , ts )
751
+ self .assertEqual (result2 , ts )
Original file line number Diff line number Diff line change @@ -133,7 +133,8 @@ def trans(x): # noqa
133
133
if dtype .tz :
134
134
# convert to datetime and change timezone
135
135
from pandas import to_datetime
136
- result = to_datetime (result ).tz_localize (dtype .tz )
136
+ result = to_datetime (result ).tz_localize ('utc' )
137
+ result = result .tz_convert (dtype .tz )
137
138
138
139
except :
139
140
pass
You can’t perform that action at this time.
0 commit comments