Skip to content

Commit 20b2333

Browse files
committed
fixed put_xminute for data has holes
1 parent 3e2e5f9 commit 20b2333

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

datafeed/datastore.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,6 @@ def _update_multi(self, symbol, quotes):
481481
i += 1
482482
pre_day = day
483483

484-
print indexes
485-
486484
for i0, i1 in indexes:
487485
t0, t1 = quotes[i0]['time'], quotes[i1-1]['time']
488486
dt = datetime.datetime.fromtimestamp(t0)
@@ -493,8 +491,15 @@ def _update_multi(self, symbol, quotes):
493491

494492
if dsi0 != 0:
495493
dsi1 = dsi1 + 1
496-
print "ds[%d:%d] = quotes[%d:%d]" % (dsi0, dsi1, i0, i1)
497-
ds[dsi0:dsi1] = sliced
494+
logging.debug("ds[%d:%d] = quotes[%d:%d]" % (dsi0, dsi1, i0, i1))
495+
try:
496+
ds[dsi0:dsi1] = sliced
497+
except TypeError:
498+
logging.debug("data may have holes")
499+
for row in sliced:
500+
r_dsi = self.timestamp_to_index(dt, row['time'])
501+
# logging.debug("r_dsi: %d" % r_dsi)
502+
ds[r_dsi] = row
498503

499504
def timestamp_to_index(self, dt, ts):
500505
day_start = time.mktime((dt.year, dt.month, dt.day,

datafeed/tests/005_na.npy

8.28 KB
Binary file not shown.

datafeed/tests/test_datastore.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_update_multi_partial_days_data(self):
323323
self.assertEqual(store.time_interval, 300)
324324
self.assertEqual(store.shape_x, 288)
325325

326-
key = '999'
326+
key = '9991'
327327
path = os.path.dirname(os.path.realpath(__file__))
328328
data = np.load(os.path.join(path, '005.npy'))
329329

@@ -337,6 +337,25 @@ def test_update_multi_partial_days_data(self):
337337
y2 = store.get(key, date)
338338
np.testing.assert_array_equal(y2[206], data[-1])
339339

340+
def test_update_multi_hold_data(self):
341+
market_minutes = 1440 # 5min data
342+
store = FiveMinute(h5py.File('%s/data.h5' % helper.datadir),
343+
market_minutes)
344+
key = '9992'
345+
path = os.path.dirname(os.path.realpath(__file__))
346+
data = np.load(os.path.join(path, '005_na.npy'))
347+
348+
store.update(key, data)
349+
350+
date = datetime.fromtimestamp(data[-1]['time']).date()
351+
y2 = store.get(key, date)
352+
353+
# Data has holes between index 171 and index 172.
354+
np.testing.assert_array_equal(y2[0], data[132])
355+
np.testing.assert_array_equal(y2[167], data[-1])
356+
np.testing.assert_array_equal(y2[39], data[171])
357+
np.testing.assert_array_equal(y2[43], data[172])
358+
340359

341360
class MinuteSnapshotCacheTest(unittest.TestCase):
342361

0 commit comments

Comments
 (0)