Skip to content

Commit

Permalink
Merge 643bf40 into 7a6b14b
Browse files Browse the repository at this point in the history
  • Loading branch information
ehebert committed May 2, 2018
2 parents 7a6b14b + 643bf40 commit a5d2765
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_history.py
Expand Up @@ -642,6 +642,23 @@ def handle_data(context, data):
with self.assertRaises(HistoryInInitialize):
test_algo.initialize()

def test_negative_bar_count(self):
"""
Negative bar counts leak future information.
"""
with self.assertRaisesRegexp(
ValueError,
"bar_count must be >= 1, but got -1"
):
self.data_portal.get_history_window(
[self.ASSET1],
pd.Timestamp('2015-01-07 14:35', tz='UTC'),
-1,
'1d',
'close',
'minute',
)

def test_daily_splits_and_mergers(self):
# self.SPLIT_ASSET and self.MERGER_ASSET had splits/mergers
# on 1/6 and 1/7
Expand Down
5 changes: 5 additions & 0 deletions zipline/data/data_portal.py
Expand Up @@ -951,6 +951,11 @@ def get_history_window(self,
if field not in OHLCVP_FIELDS and field != 'sid':
raise ValueError("Invalid field: {0}".format(field))

if bar_count < 1:
raise ValueError(
"bar_count must be >= 1, but got {}".format(bar_count)
)

if frequency == "1d":
if field == "price":
df = self._get_history_daily_window(assets, end_dt, bar_count,
Expand Down

0 comments on commit a5d2765

Please sign in to comment.