Skip to content

Commit 54b54f8

Browse files
committed
BUG: fix downsampling bug with intraday data when end.time() < start.time(). close #1772
1 parent 3151662 commit 54b54f8

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ pandas 0.9.0
143143
- Fixes to Period.start_time for non-daily frequencies (#1857)
144144
- Fix failure when converter used on index_col in read_csv (#1835)
145145
- Implement PeriodIndex.append so that pandas.concat works correctly (#1815)
146+
- Avoid Cython out-of-bounds access causing segfault sometimes in pad_2d,
147+
backfill_2d
148+
- Fix resampling error with intraday times and anchored target time (like
149+
AS-DEC) (#1772)
146150

147151
pandas 0.8.1
148152
============

pandas/tseries/resample.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pandas.tseries.index import DatetimeIndex, date_range
88
from pandas.tseries.offsets import DateOffset, Tick, _delta_to_nanoseconds
99
from pandas.tseries.period import PeriodIndex, period_range
10+
import pandas.tseries.tools as tools
1011
import pandas.core.common as com
1112

1213
from pandas.lib import Timestamp
@@ -276,12 +277,18 @@ def _get_range_edges(axis, offset, closed='left', base=0):
276277
return _adjust_dates_anchored(axis[0], axis[-1], offset,
277278
closed=closed, base=base)
278279

280+
first, last = axis[0], axis[-1]
281+
if not isinstance(offset, Tick):# and first.time() != last.time():
282+
# hack!
283+
first = tools.normalize_date(first)
284+
last = tools.normalize_date(last)
285+
279286
if closed == 'left':
280-
first = Timestamp(offset.rollback(axis[0]))
287+
first = Timestamp(offset.rollback(first))
281288
else:
282-
first = Timestamp(axis[0] - offset)
289+
first = Timestamp(first - offset)
283290

284-
last = Timestamp(axis[-1] + offset)
291+
last = Timestamp(last + offset)
285292

286293
return first, last
287294

pandas/tseries/tests/test_resample.py

+12
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,18 @@ def test_how_lambda_functions(self):
559559
tm.assert_series_equal(result['foo'], foo_exp)
560560
tm.assert_series_equal(result['bar'], bar_exp)
561561

562+
def test_resample_unequal_times(self):
563+
# #1772
564+
start = datetime(1999, 3, 1, 5)
565+
# end hour is less than start
566+
end = datetime(2012, 7, 31, 4)
567+
bad_ind = date_range(start, end, freq="30min")
568+
df = DataFrame({'close':1}, index=bad_ind)
569+
570+
# it works!
571+
df.resample('AS', 'sum')
572+
573+
562574
def _simple_ts(start, end, freq='D'):
563575
rng = date_range(start, end, freq=freq)
564576
return Series(np.random.randn(len(rng)), index=rng)

0 commit comments

Comments
 (0)