Skip to content

Commit ed20b1d

Browse files
committed
Merge pull request #6477 from jreback/resample
BUG: Bug in resample with a timezone and certain offsets (GH6397)
2 parents 878ccea + 3896559 commit ed20b1d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Bug Fixes
176176
- Bug in ``str.split`` when passed ``pat=None`` and ``n=1`` (:issue:`6466`)
177177
- Bug in ``io.data.DataReader`` when passed ``"F-F_Momentum_Factor"`` and ``data_source="famafrench"`` (:issue:`6460`)
178178
- Bug in ``sum`` of a ``timedelta64[ns]`` series (:issue:`6462`)
179+
- Bug in ``resample`` with a timezone and certain offsets (:issue:`6397`)
179180

180181
pandas 0.13.1
181182
-------------

pandas/tseries/index.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,13 @@ def _can_fast_union(self, other):
10671067
left_end = left[-1]
10681068

10691069
# Only need to "adjoin", not overlap
1070-
return (right_start == left_end + offset) or right_start in left
1070+
try:
1071+
return (right_start == left_end + offset) or right_start in left
1072+
except (ValueError):
1073+
1074+
# if we are comparing an offset that does not propogate timezones
1075+
# this will raise
1076+
return False
10711077

10721078
def _fast_union(self, other):
10731079
if len(other) == 0:

pandas/tseries/tests/test_resample.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,18 @@ def test_resample_tz_localized(self):
973973
expected = Series([1.5], index=ex_index)
974974
assert_series_equal(result, expected)
975975

976+
# GH 6397
977+
# comparing an offset that doesn't propogate tz's
978+
rng = date_range('1/1/2011', periods=20000, freq='H')
979+
rng = rng.tz_localize('EST')
980+
ts = DataFrame(index=rng)
981+
ts['first']=np.random.randn(len(rng))
982+
ts['second']=np.cumsum(np.random.randn(len(rng)))
983+
expected = DataFrame({ 'first' : ts.resample('A',how=np.sum)['first'],
984+
'second' : ts.resample('A',how=np.mean)['second'] },columns=['first','second'])
985+
result = ts.resample('A', how={'first':np.sum, 'second':np.mean}).reindex(columns=['first','second'])
986+
assert_frame_equal(result,expected)
987+
976988
def test_closed_left_corner(self):
977989
# #1465
978990
s = Series(np.random.randn(21),

0 commit comments

Comments
 (0)