MAINT: Check dates before computing factor_matrix.

In SimpleFFCEngine.factor_matrix barf with a useful error if end_date <=
start_date.
This commit is contained in:
Scott Sanderson
2015-08-03 12:02:34 -04:00
parent 5da03d2df5
commit 7bb20eb297
2 changed files with 16 additions and 0 deletions
+10
View File
@@ -85,6 +85,16 @@ class ConstantInputTestCase(TestCase):
)
self.asset_finder = AssetFinder(self.asset_info)
def test_bad_dates(self):
loader = self.loader
engine = SimpleFFCEngine(loader, self.dates, self.asset_finder)
msg = "start_date must be before end_date .*"
with self.assertRaisesRegexp(ValueError, msg):
engine.factor_matrix({}, self.dates[2], self.dates[1])
with self.assertRaisesRegexp(ValueError, msg):
engine.factor_matrix({}, self.dates[2], self.dates[2])
def test_single_factor(self):
loader = self.loader
engine = SimpleFFCEngine(loader, self.dates, self.asset_finder)
+6
View File
@@ -226,6 +226,12 @@ class SimpleFFCEngine(object):
--------
FFCEngine.factor_matrix
"""
if end_date <= start_date:
raise ValueError(
"start_date must be before end_date \n"
"start_date=%s, end_date=%s" % (start_date, end_date)
)
graph = build_dependency_graph(terms.values())
ordered_terms = topological_sort(graph)
extra_row_counts = get_node_attributes(graph, 'extra_rows')