Skip to content

Commit

Permalink
make _to_dict() public (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwcantrell authored Dec 21, 2020
1 parent a1acaff commit d0a46ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions empress/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,20 @@ def make_empress(self):
main_template = self._get_template()

# _process_data does a lot of munging to the coordinates data and
# _to_dict puts the data into a dictionary-like object for consumption
data = self._to_dict()
# to_dict puts the data into a dictionary-like object for consumption
data = self.to_dict()

plot = main_template.render(data)

return plot

def _to_dict(self):
def to_dict(self):
"""Convert processed data into a dictionary
Warning: the object returned by to_dict will contain references to
internal variables. Exercise caution if modifying the value of objects
returned by to_dict.
Returns
-------
dict
Expand Down
12 changes: 6 additions & 6 deletions tests/python/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_to_dict(self):
viz = Empress(self.tree, self.table, self.sample_metadata,
shear_to_table=False)

obs = viz._to_dict()
obs = viz.to_dict()
dict_a_cp = copy.deepcopy(DICT_A)

# NOTE: Uncomment the following two lines of code to write the current
Expand All @@ -315,7 +315,7 @@ def test_to_dict_with_feature_metadata(self):
self.tree, self.table, self.sample_metadata, self.feature_metadata,
shear_to_table=False
)
obs = viz._to_dict()
obs = viz.to_dict()
dict_a_with_fm = copy.deepcopy(DICT_A)
dict_a_with_fm["compressed_tip_metadata"] = {1: ["asdf", "qwer"]}
dict_a_with_fm["compressed_int_metadata"] = {8: ["ghjk", "tyui"]}
Expand All @@ -333,7 +333,7 @@ def test_to_dict_with_metadata_nans(self):
viz = Empress(self.tree, self.table, nan_sample_metadata,
nan_feature_metadata,
shear_to_table=False)
obs = viz._to_dict()
obs = viz.to_dict()
dict_a_nan = copy.deepcopy(DICT_A)

# [1][3] corresponds to Sample2, Metadata4
Expand All @@ -355,7 +355,7 @@ def test_to_dict_with_emperor(self):
ordination=self.pcoa,
shear_to_table=False,
filter_extra_samples=True)
obs = viz._to_dict()
obs = viz.to_dict()

self.assertEqual(viz._emperor.width, '50vw')
self.assertEqual(viz._emperor.height, '100vh; float: right')
Expand Down Expand Up @@ -418,7 +418,7 @@ def test_to_dict_tree_plot(self):
dict_a_cp = copy.deepcopy(DICT_A)
self._clear_copied_dict_a(dict_a_cp)

obs = viz._to_dict()
obs = viz.to_dict()
self.assertEqual(obs, dict_a_cp)

def test_to_dict_tree_plot_with_feature_metadata(self):
Expand All @@ -432,7 +432,7 @@ def test_to_dict_tree_plot_with_feature_metadata(self):
dict_a_cp["compressed_int_metadata"] = {8: ["ghjk", "tyui"]}
dict_a_cp["feature_metadata_columns"] = ["fmdcol1", "fmdcol2"]

obs = viz._to_dict()
obs = viz.to_dict()
self.assertEqual(obs, dict_a_cp)

def test_shear_tree_to_table(self):
Expand Down

0 comments on commit d0a46ed

Please sign in to comment.