Skip to content

Commit

Permalink
support file-like objects for report.save_html (#854)
Browse files Browse the repository at this point in the history
Co-authored-by: Vyacheslav Morov <[email protected]>
  • Loading branch information
mike0sv and Liraim authored Nov 14, 2023
1 parent 812b94b commit 2b7a0af
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/evidently/suite/base_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import uuid
from datetime import datetime
from typing import IO
from typing import Dict
from typing import Iterator
from typing import List
Expand Down Expand Up @@ -179,7 +180,7 @@ def get_html(self):
)
return self._render(determine_template("inline"), template_params)

def save_html(self, filename: str, mode: Union[str, SaveMode] = SaveMode.SINGLE_FILE):
def save_html(self, filename: Union[str, IO], mode: Union[str, SaveMode] = SaveMode.SINGLE_FILE):
dashboard_id, dashboard_info, graphs = self._build_dashboard_info()
if isinstance(mode, str):
_mode = SaveModeMap.get(mode)
Expand All @@ -192,9 +193,15 @@ def save_html(self, filename: str, mode: Union[str, SaveMode] = SaveMode.SINGLE_
dashboard_info=dashboard_info,
additional_graphs=graphs,
)
with open(filename, "w", encoding="utf-8") as out_file:
out_file.write(self._render(determine_template("inline"), template_params))
render = self._render(determine_template("inline"), template_params)
if isinstance(filename, str):
with open(filename, "w", encoding="utf-8") as out_file:
out_file.write(render)
else:
filename.write(render)
else:
if not isinstance(filename, str):
raise ValueError("Only singlefile save mode supports streams")
font_file, lib_file = save_lib_files(filename, mode)
data_file = save_data_file(filename, mode, dashboard_id, dashboard_info, graphs)
template_params = TemplateParams(
Expand Down

0 comments on commit 2b7a0af

Please sign in to comment.