Skip to content

Commit d0bc95d

Browse files
author
reasto
committed
Top level read fix for pandas-dev#95
1 parent db7adb8 commit d0bc95d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

arctic/tickstore/toplevel.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,16 @@ def add(self, date_range, library_name):
100100

101101
def read(self, symbol, date_range, columns=['BID', 'ASK', 'TRDPRC_1', 'BIDSIZE', 'ASKSIZE', 'TRDVOL_1'], include_images=False):
102102
libraries = self._get_libraries(date_range)
103-
dfs = [l.library.read(symbol, l.date_range.intersection(date_range), columns,
104-
include_images=include_images) for l in libraries]
103+
dfs = []
104+
for l in libraries:
105+
try:
106+
df = l.library.read(symbol, l.date_range.intersection(date_range), columns,
107+
include_images=include_images)
108+
dfs.append(df)
109+
except NoDataFoundException, e:
110+
continue
111+
if len(dfs) == 0:
112+
raise NoDataFoundException("No Data found for {} in range: {}".format(symbol, date_range))
105113
return pd.concat(dfs)
106114

107115
def write(self, symbol, data):

tests/integration/tickstore/test_toplevel.py

+22
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ def test_should_return_data_when_date_range_spans_libraries(toplevel_tickstore,
8888
assert_frame_equal(expected_df, res.tz_convert(mktz('Europe/London')))
8989

9090

91+
def test_should_return_data_when_date_range_spans_libraries_even_if_one_returns_nothing(toplevel_tickstore, arctic):
92+
arctic.initialize_library('FEED_2010.LEVEL1', tickstore.TICK_STORE_TYPE)
93+
arctic.initialize_library('FEED_2011.LEVEL1', tickstore.TICK_STORE_TYPE)
94+
tickstore_2010 = arctic['FEED_2010.LEVEL1']
95+
tickstore_2011 = arctic['FEED_2011.LEVEL1']
96+
toplevel_tickstore._collection.insert_one({'start': dt(2010, 1, 1),
97+
'end': dt(2010, 12, 31, 23, 59, 59),
98+
'library_name': 'FEED_2010.LEVEL1'})
99+
toplevel_tickstore._collection.insert_one({'start': dt(2011, 1, 1),
100+
'end': dt(2011, 12, 31, 23, 59, 59),
101+
'library_name': 'FEED_2011.LEVEL1'})
102+
dates = pd.date_range('20100101', periods=6, tz=mktz('Europe/London'))
103+
df_10 = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
104+
tickstore_2010.write('blah', df_10)
105+
dates = pd.date_range('20110201', periods=6, tz=mktz('Europe/London'))
106+
df_11 = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
107+
tickstore_2011.write('blah', df_11)
108+
res = toplevel_tickstore.read('blah', DateRange(start=dt(2010, 1, 2), end=dt(2011, 1, 4)), list('ABCD'))
109+
expected_df = df_10[1:]
110+
assert_frame_equal(expected_df, res.tz_convert(mktz('Europe/London')))
111+
112+
91113
def test_should_add_underlying_library_where_none_exists(toplevel_tickstore, arctic):
92114
arctic.initialize_library('FEED_2010.LEVEL1', tickstore.TICK_STORE_TYPE)
93115
toplevel_tickstore.add(DateRange(start=dt(2010, 1, 1), end=dt(2010, 12, 31, 23, 59, 59, 999000)), 'FEED_2010.LEVEL1')

0 commit comments

Comments
 (0)