def test_cant_send_access(self): self.protocol.broke() try: ds.frame(stack="plots/my_plot") self.fail("Error must be raised in send_access()") except RuntimeError: pass
def test_add(self): stack = "my_stack" frame = ds.frame(stack=stack) params = {"my param": 1, "x": 2} frame.add(self.get_figure(), **params) frame.push(ds.FrameMeta(message="test", y=10)) attachments = self.get_data(stack)["attachments"] self.assertEqual(2, len(attachments[0]["params"])) self.assertEqual(2, attachments[0]["params"]["x"]) self.assertEqual(1, attachments[0]["params"]["my param"]) ps = self.get_data(stack)["params"] self.assertEqual(2, len(ps)) self.assertEqual("test", ps["message"]) self.assertEqual(10, ps["y"])
def test_single_plot(self): frame = ds.frame(stack="plots/my_plot") t = np.arange(0.0, 2.0, 0.01) s = 1 + np.sin(2 * np.pi * t) fig, ax = plt.subplots() ax.plot(t, s) my_desc = "My first plot" ax.set(xlabel="t", ylabel="x", title=my_desc) ax.grid() frame.add(fig, my_desc) frame.push() self.assertIn("user/plots/my_plot", self.protocol.data) attachments = self.get_data("plots/my_plot")["attachments"] self.assertIsNotNone(self.get_data("plots/my_plot")["id"]) self.assertEqual("my_token", self.protocol.token) self.assertEqual(1, len(attachments)) self.assertEqual("image/svg+xml", attachments[0]["content_type"]) self.assertEqual("matplotlib", attachments[0]["application"]) self.assertNotIn("params", attachments[0].keys()) self.assertEqual(my_desc, attachments[0]["description"])
def test_multiple_plots(self): stack = "plots/my_plot" frame = ds.frame(stack=stack) p = np.arange(0.0, 1.0, 0.1) for idx, phase in enumerate(p): t = np.arange(0.0, 2.0, 0.01) s = 1 + np.sin(2 * np.pi * t + phase) fig, ax = plt.subplots() ax.plot(t, s) ax.set(xlabel="t", ylabel="x", title="Plot with parameters") ax.grid() frame.add(fig, params={"phase": phase, "index": idx}) frame.push() attachments = self.get_data(stack)["attachments"] self.assertEqual(len(p), len(attachments)) for idx, phase in enumerate(p): att = attachments[idx] self.assertNotIn("description", att.keys()) self.assertEqual(2, len(att["params"].keys())) self.assertEqual(idx, att["params"]["index"]) self.assertEqual(phase, att["params"]["phase"])
df = get_data() row = df[df["Company"] == companies.value()].filter( ["y2015", "y2016", "y2017", "y2018", "y2019"], axis=1) row.rename(columns={ "y2015": "2015", "y2016": "2016", "y2017": "2017", "y2018": "2018", "y2019": "2019" }, inplace=True) col = row.transpose() col.rename(columns={col.columns[0]: "Licenses"}, inplace=True) fig = px.bar(col.reset_index(), x="index", y="Licenses", labels={"index": "Year"}) fig.update(layout_showlegend=False) self.data = fig data_by_company_app = ds.app( controls=[companies], outputs=[ctrl.Output(handler=company_output_handler)]) frame = ds.frame("tabs") frame.add(data_by_country_app, params={"Companies": ds.tab()}) frame.add(data_by_company_app, params={"Licenses": ds.tab()}) result = frame.push() print(result.url)
from dstack import frame from dstack.cli.installer import Installer from pathlib import Path if __name__ == '__main__': frame = frame(Installer._JDK_STACK_BASE + "/8") frame.add(Path("jdk/8/bellsoft-jre8u282+8-macos-amd64.zip"), os="Darwin-x86_64") frame.add(Path("jdk/8/bellsoft-jre8u282+8-linux-amd64.tar.gz"), os="Linux-x86_64") frame.add(Path("jdk/8/bellsoft-jre8u282+8-windows-amd64.zip"), os="Windows-AMD64") print(frame.push())
def test_stack_absolute_path(self): frame = ds.frame(stack="/other/my_plot") frame.add(self.get_figure()) frame.push() self.assertIn(f"other/my_plot", self.protocol.data)
def test_stack_relative_path(self): frame = ds.frame(stack="plots/my_plot") frame.add(self.get_figure()) frame.push() self.assertIn(f"user/plots/my_plot", self.protocol.data)