Skip to content

Commit de8f14d

Browse files
author
Chang She
committed
BUG: out of bounds on buffer access if time doesn't exist in TimeSeries.at_time
1 parent 460f8d3 commit de8f14d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pandas/src/tseries.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,13 @@ def convert_timestamps(ndarray values):
476476

477477
return out
478478

479-
480-
481479
def maybe_indices_to_slice(ndarray[int64_t] indices):
482480
cdef:
483481
Py_ssize_t i, n = len(indices)
484482

483+
if n == 0:
484+
return indices
485+
485486
for i in range(1, n):
486487
if indices[i] - indices[i - 1] != 1:
487488
return indices

pandas/tseries/tests/test_timeseries.py

+6
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ def test_at_time(self):
789789
result = ts.at_time(time(0, 0))
790790
assert_series_equal(result, ts)
791791

792+
# time doesn't exist
793+
rng = date_range('1/1/2012', freq='23Min', periods=384)
794+
ts = Series(np.random.randn(len(rng)), rng)
795+
rs = ts.at_time('16:00')
796+
self.assert_(len(rs) == 0)
797+
792798
def test_between_time(self):
793799
rng = date_range('1/1/2000', '1/5/2000', freq='5min')
794800
ts = Series(np.random.randn(len(rng)), index=rng)

0 commit comments

Comments
 (0)