Skip to content

Commit

Permalink
Merge pull request #542 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
ENH: model_collection_result and hypothesis_result get name attribute
  • Loading branch information
GavinHuttley committed Feb 19, 2020
2 parents f925fd3 + dd4bf34 commit 15beb0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/cogent3/app/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,14 @@ class model_collection_result(generic_result):

_type = "model_collection_result"

def __init__(self, source=None):
def __init__(self, name=None, source=None):
"""
alt
either a likelihood function instance
"""
super(model_collection_result, self).__init__(source)
self._construction_kwargs.update({"name": name})
self._name = name

def _get_repr_data_(self):
rows = []
Expand All @@ -385,7 +387,7 @@ def _get_repr_data_(self):
row = [repr(key)] + [getattr(member, a) for a in attrs]
rows.append(row)

table = Table(header=["key"] + attrs, rows=rows)
table = Table(header=["key"] + attrs, rows=rows, title=self.name)
table = table.sorted(columns="nfp")
return table

Expand All @@ -397,6 +399,10 @@ def __repr__(self):
table = self._get_repr_data_()
return str(table._get_repr_())

@property
def name(self):
return self._name

def select_models(self, stat="aicc", threshold=0.05):
"""returns models satisfying stat threshold.
Parameters
Expand Down Expand Up @@ -464,12 +470,12 @@ class hypothesis_result(model_collection_result):

_type = "hypothesis_result"

def __init__(self, name_of_null, source=None):
def __init__(self, name_of_null, name=None, source=None):
"""
alt
either a likelihood function instance
"""
super(hypothesis_result, self).__init__(source)
super(hypothesis_result, self).__init__(name=name, source=source)
self._construction_kwargs = dict(name_of_null=name_of_null, source=source)

self._name_of_null = name_of_null
Expand All @@ -486,7 +492,7 @@ def _get_repr_data_(self):
row = status_name + [getattr(member, a) for a in attrs]
rows.append(row)

table = Table(header=["hypothesis", "key"] + attrs, rows=rows)
table = Table(header=["hypothesis", "key"] + attrs, rows=rows, title=self.name)
table = table.sorted(columns="nfp")
stats = [[self.LR, self.df, self.pvalue]]
stats = Table(header=["LR", "df", "pvalue"], rows=stats, title="Statistics")
Expand Down
6 changes: 5 additions & 1 deletion tests/test_app/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,16 @@ def test_model_collection_result_repr(self):

def test_json_roundtrip(self):
"""roundtrip from json correct"""
coll = model_collection_result(None)
coll = model_collection_result(name="blah", source="blah2")
coll.update(self._model_results)
self.assertEqual(coll.name, "blah")
self.assertEqual(coll.source, "blah2")
orig = coll.__repr__()
got = deserialise_object(coll.to_json())
self.assertEqual(got.__repr__(), orig)
self.assertIsInstance(got, model_collection_result)
self.assertEqual(got.name, coll.name)
self.assertEqual(got.source, coll.source)


if __name__ == "__main__":
Expand Down

0 comments on commit 15beb0a

Please sign in to comment.