|
32 | 32 | import pandas.core.nanops as nanops
|
33 | 33 |
|
34 | 34 | import pandas.util.testing as tm
|
| 35 | +import pytz |
35 | 36 | import pandas as pd
|
36 | 37 | from numpy.testing import assert_equal
|
37 | 38 |
|
@@ -4096,6 +4097,27 @@ def test_groupby_with_empty(self):
|
4096 | 4097 | grouped = series.groupby(grouper)
|
4097 | 4098 | assert next(iter(grouped), None) is None
|
4098 | 4099 |
|
| 4100 | + def test_groupby_with_timezone_selection(self): |
| 4101 | + # GH 11616 |
| 4102 | + # Test that column selection returns output in correct timezone. |
| 4103 | + np.random.seed(42) |
| 4104 | + df = pd.DataFrame({ |
| 4105 | + 'factor': np.random.randint(0, 3, size=60), |
| 4106 | + 'time': pd.date_range('01/01/2000 00:00', periods=60, freq='s', tz='UTC') |
| 4107 | + }) |
| 4108 | + df1 = df.groupby('factor').max()['time'] |
| 4109 | + df2 = df.groupby('factor')['time'].max() |
| 4110 | + tm.assert_series_equal(df1, df2) |
| 4111 | + |
| 4112 | + def test_timezone_info(self): |
| 4113 | + #GH 11682 |
| 4114 | + # Timezone info lost when broadcasting scalar datetime to DataFrame |
| 4115 | + df = pd.DataFrame({'a': [1], 'b': [datetime.now(pytz.utc)]}) |
| 4116 | + tm.assert_equal(df['b'][0].tzinfo, pytz.utc) |
| 4117 | + df = pd.DataFrame({'a': [1,2,3]}) |
| 4118 | + df['b'] = datetime.now(pytz.utc) |
| 4119 | + tm.assert_equal(df['b'][0].tzinfo, pytz.utc) |
| 4120 | + |
4099 | 4121 | def test_groupby_with_timegrouper(self):
|
4100 | 4122 | # GH 4161
|
4101 | 4123 | # TimeGrouper requires a sorted index
|
|
0 commit comments