Skip to content

Commit

Permalink
BUG: Fixes should_clean for keep_last=0
Browse files Browse the repository at this point in the history
  • Loading branch information
richafrank committed Aug 17, 2016
1 parent 440806a commit fcf1067
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 21 additions & 1 deletion tests/data/bundles/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from zipline.assets.synthetic import make_simple_equity_info
from zipline.data.bundles import UnknownBundle, from_bundle_ingest_dirname
from zipline.data.bundles.core import _make_bundle_core
from zipline.data.bundles.core import _make_bundle_core, BadClean
from zipline.lib.adjustment import Float64Multiply
from zipline.pipeline.loaders.synthetic import (
make_bar_data,
Expand Down Expand Up @@ -369,6 +369,26 @@ def test_clean_keep_last(self):
msg='keep_last=2 did not remove the correct number of ingestions',
)

with assert_raises(BadClean):
self.clean('bundle', keep_last=-1, environ=self.environ)

assert_equal(
self._list_bundle(),
{fourth, fifth},
msg='keep_last=-1 removed some ingestions',
)

assert_equal(
self.clean('bundle', keep_last=0, environ=self.environ),
{fourth, fifth},
)

assert_equal(
self._list_bundle(),
set(),
msg='keep_last=0 did not remove the correct number of ingestions',
)

@staticmethod
def _ts_of_run(run):
return from_bundle_ingest_dirname(run.rsplit(os.path.sep, 1)[-1])
Expand Down
8 changes: 5 additions & 3 deletions zipline/data/bundles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib2 import ExitStack
import click
import pandas as pd
from toolz import curry, complement
from toolz import curry, complement, take

from ..us_equity_pricing import (
BcolzDailyBarReader,
Expand Down Expand Up @@ -563,11 +563,13 @@ def should_clean(name):
(after is not None and dt > after)
)

else:
last_n_dts = set(all_runs[-keep_last:])
elif keep_last >= 0:
last_n_dts = set(take(keep_last, reversed(all_runs)))

def should_clean(name):
return name not in last_n_dts
else:
raise BadClean(before, after, keep_last)

cleaned = set()
for run in all_runs:
Expand Down

0 comments on commit fcf1067

Please sign in to comment.