Skip to content

Commit

Permalink
fix(eda.report):encoding and show issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhenmao committed Nov 28, 2020
1 parent 3d6d61b commit 721ae7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
25 changes: 24 additions & 1 deletion dataprep/eda/create_report/report.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
This module implements the Report class.
"""
import sys
import webbrowser
from typing import Optional
from pathlib import Path
from tempfile import NamedTemporaryFile
from ...utils import is_notebook


CELL_HEIGHT_OVERRIDE = """<style>
Expand Down Expand Up @@ -72,6 +74,27 @@ def show_browser(self) -> None:

with NamedTemporaryFile(suffix=".html", delete=False) as tmpf:
pass
with open(tmpf.name, "w") as file:
with open(tmpf.name, "w", encoding="utf-8") as file:
file.write(self.report)
webbrowser.open(f"file://{tmpf.name}", new=2)

def show(self) -> None:
"""
Render the report. This is useful when calling plot in a for loop.
"""
# if not called from notebook environment, ref to show_browser function.
if not is_notebook():
print(
"The plot will not show in a notebook environment, "
"please try 'show_browser' if you want to open it in browser",
file=sys.stderr,
)
try:
from IPython.display import ( # pylint: disable=import-outside-toplevel
HTML,
display,
)

display(HTML(self._repr_html_()))
except ImportError:
pass
11 changes: 11 additions & 0 deletions dataprep/tests/eda/test_create_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ def test_report(simpledf: pd.DataFrame) -> None:

matplotlib.use("PS")
create_report(simpledf, mode="basic")


def test_report_show(simpledf: pd.DataFrame) -> None:
from sys import platform

if platform == "darwin":
import matplotlib

matplotlib.use("PS")
report = create_report(simpledf, mode="basic")
report.show()

0 comments on commit 721ae7b

Please sign in to comment.