Skip to content

Commit

Permalink
bugfix: change plots filename (#273)
Browse files Browse the repository at this point in the history
* bugfix: change plots filename

When multiple zn.plots where defined they would overwrite each other. Using different filenames prohibits this.

* add test for writing two plots
  • Loading branch information
PythonFZ authored Apr 12, 2022
1 parent d836039 commit d6a44dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/integration_tests/test_zn_plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import shutil
import subprocess

Expand Down Expand Up @@ -66,3 +67,27 @@ def test_write_plots_value_error(proj_path):
def test_write_plots_type_error(proj_path):
with pytest.raises(TypeError):
WritePlotsWrongData().run_and_save()


class WriteTwoPlots(Node):
plots_a: pd.DataFrame = zn.plots()
plots_b: pd.DataFrame = zn.plots()

def run(self):
self.plots_a = pd.DataFrame({"value": [x for x in range(100)]})
self.plots_a.index.name = "my_index_a"

self.plots_b = pd.DataFrame({"value": [-x for x in range(100)]})
self.plots_b.index.name = "my_index_b"


def test_write_two_plots(proj_path):
WriteTwoPlots().write_graph(no_exec=False)
subprocess.check_call(["dvc", "plots", "show"])

wp = WriteTwoPlots.load()
assert wp.plots_a.index.name == "my_index_a"
assert wp.plots_b.index.name == "my_index_b"

assert pathlib.Path("nodes", "WriteTwoPlots", "plots_a.csv").exists()
assert pathlib.Path("nodes", "WriteTwoPlots", "plots_b.csv").exists()
2 changes: 1 addition & 1 deletion zntrack/zn/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class plots(ZnTrackOption):

def get_filename(self, instance) -> pathlib.Path:
"""Overwrite filename to csv"""
return pathlib.Path("nodes", instance.node_name, f"{self.dvc_option}.csv")
return pathlib.Path("nodes", instance.node_name, f"{self.name}.csv")

def save(self, instance):
"""Save value with pd.DataFrame.to_csv"""
Expand Down

0 comments on commit d6a44dd

Please sign in to comment.