Skip to content

Commit 57c24a3

Browse files
ahcubTomAugspurger
authored andcommitted
!I fix for BUG: resample with tz-aware: Values falls after last bin pandas-dev#15549 (pandas-dev#18337)
(cherry picked from commit 8efd1a0)
1 parent 3a1eeef commit 57c24a3

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

doc/source/whatsnew/v0.21.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Bug Fixes
6262
- Bug in ``pd.Series.rolling.skew()`` and ``rolling.kurt()`` with all equal values has floating issue (:issue:`18044`)
6363
- Bug in ``pd.DataFrameGroupBy.count()`` when counting over a datetimelike column (:issue:`13393`)
6464
- Bug in ``pd.concat`` when empty and non-empty DataFrames or Series are concatenated (:issue:`18178` :issue:`18187`)
65+
- Bug in ``DataFrame.resample(...)`` when there is a time change (DST) and resampling frequecy is 12h or higher (:issue:`15549`)
66+
- Bug in :class:`IntervalIndex` constructor when a list of intervals is passed with non-default ``closed`` (:issue:`18334`)
67+
- Bug in :meth:`IntervalIndex.copy` when copying and ``IntervalIndex`` with non-default ``closed`` (:issue:`18339`)
6568

6669
Conversion
6770
^^^^^^^^^^

pandas/core/resample.py

+10
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,16 @@ def _get_time_bins(self, ax):
11411141
tz=tz,
11421142
name=ax.name)
11431143

1144+
# GH 15549
1145+
# In edge case of tz-aware resapmling binner last index can be
1146+
# less than the last variable in data object, this happens because of
1147+
# DST time change
1148+
if len(binner) > 1 and binner[-1] < last:
1149+
extra_date_range = pd.date_range(binner[-1], last + self.freq,
1150+
freq=self.freq, tz=tz,
1151+
name=ax.name)
1152+
binner = labels = binner.append(extra_date_range[1:])
1153+
11441154
# a little hack
11451155
trimmed = False
11461156
if (len(binner) > 2 and binner[-2] == last and

pandas/tests/test_resample.py

+28
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,34 @@ def test_resample_weekly_bug_1726(self):
27292729
# it works!
27302730
df.resample('W-MON', closed='left', label='left').first()
27312731

2732+
def test_resample_with_dst_time_change(self):
2733+
# GH 15549
2734+
index = pd.DatetimeIndex([1457537600000000000, 1458059600000000000],
2735+
tz='UTC').tz_convert('America/Chicago')
2736+
df = pd.DataFrame([1, 2], index=index)
2737+
result = df.resample('12h', closed='right',
2738+
label='right').last().ffill()
2739+
2740+
expected_index_values = ['2016-03-09 12:00:00-06:00',
2741+
'2016-03-10 00:00:00-06:00',
2742+
'2016-03-10 12:00:00-06:00',
2743+
'2016-03-11 00:00:00-06:00',
2744+
'2016-03-11 12:00:00-06:00',
2745+
'2016-03-12 00:00:00-06:00',
2746+
'2016-03-12 12:00:00-06:00',
2747+
'2016-03-13 00:00:00-06:00',
2748+
'2016-03-13 13:00:00-05:00',
2749+
'2016-03-14 01:00:00-05:00',
2750+
'2016-03-14 13:00:00-05:00',
2751+
'2016-03-15 01:00:00-05:00',
2752+
'2016-03-15 13:00:00-05:00']
2753+
index = pd.DatetimeIndex(expected_index_values,
2754+
tz='UTC').tz_convert('America/Chicago')
2755+
expected = pd.DataFrame([1.0, 1.0, 1.0, 1.0, 1.0,
2756+
1.0, 1.0, 1.0, 1.0, 1.0,
2757+
1.0, 1.0, 2.0], index=index)
2758+
assert_frame_equal(result, expected)
2759+
27322760
def test_resample_bms_2752(self):
27332761
# GH2753
27342762
foo = pd.Series(index=pd.bdate_range('20000101', '20000201'))

0 commit comments

Comments
 (0)