Skip to content

Commit

Permalink
Added "open_browser" option for show_html(), under-the-hood correlati…
Browse files Browse the repository at this point in the history
…on error flagging
  • Loading branch information
fbdesignpro committed Oct 9, 2020
1 parent 7695312 commit 7dd8988
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
23 changes: 13 additions & 10 deletions sweetviz/dataframe_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sweetviz.series_analyzer as sa
import sweetviz.utils as su
from sweetviz.graph_associations import GraphAssoc
from sweetviz.graph_associations import CORRELATION_ERROR
from sweetviz.graph_legend import GraphLegend
from sweetviz.config import config
import sweetviz.sv_html as sv_html
Expand Down Expand Up @@ -268,24 +269,26 @@ def __getitem__(self, key):
def __setitem__(self, key, value):
self._features[key] = value

def show_html(self, filepath='SWEETVIZ_REPORT.html', layout='widescreen'):
# OUTPUT
# ----------------------------------------------------------------------------------------------
def show_html(self, filepath='SWEETVIZ_REPORT.html', open_browser=True, layout='widescreen'):
sv_html.load_layout_globals_from_config()
self.page_layout = layout
sv_html.set_summary_positions(self)
sv_html.generate_html_detail(self)
self._page_html = sv_html.generate_html_dataframe_page(self)

# self.temp_folder = config["Files"].get("temp_folder")
# os.makedirs(os.path.normpath(self.temp_folder), exist_ok=True)

f = open(filepath, 'w', encoding="utf-8")
f.write(self._page_html)
f.close()

print(f"Report {filepath} was generated! NOTEBOOK/COLAB USERS: no browser will pop up, the report is saved in your notebook/colab files.")
# Not sure how to work around this: not fatal but annoying...Notebook/colab
# https://bugs.python.org/issue5993
webbrowser.open('file://' + os.path.realpath(filepath))
if open_browser:
print(f"Report {filepath} was generated! NOTEBOOK/COLAB USERS: no browser will pop up, the report is saved in your notebook/colab files.")
# Not sure how to work around this: not fatal but annoying...Notebook/colab
# https://bugs.python.org/issue5993
webbrowser.open('file://' + os.path.realpath(filepath))
else:
print(f"Report {filepath} was generated!")

@staticmethod
def get_predetermined_type(name: str,
Expand Down Expand Up @@ -425,15 +428,15 @@ def mirror_association(association_dict, feature_name, other_name, value):
feature.source.corr(other.source, method='pearson')
# TODO: display correlation error better in graph!
if isnan(cur_associations[other.source.name]):
cur_associations[other.source.name] = 0.0
cur_associations[other.source.name] = CORRELATION_ERROR
mirror_association(self._associations, feature_name, other.source.name, \
cur_associations[other.source.name])
if process_compare:
cur_associations_compare[other.source.name] = \
feature.compare.corr(other.compare, method='pearson')
# TODO: display correlation error better in graph!
if isnan(cur_associations_compare[other.source.name]):
cur_associations_compare[other.source.name] = 0.0
cur_associations_compare[other.source.name] = CORRELATION_ERROR
mirror_association(self._associations_compare, feature_name, other.source.name, \
cur_associations_compare[other.source.name])
self.progress_bar.update(1)
9 changes: 9 additions & 0 deletions sweetviz/graph_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
# A name for a custom index column that likely will not be used by users
UNIQUE_INDEX_NAME = 'indexZZ8vr$#RVwadfaFASDFSA'

# Something to detect correlation errors to display
# TODO: Better/more intuitive display of correlation errors (right now just show up as empty)
CORRELATION_ERROR = 83572398457329.0

class GraphAssoc(sweetviz.graph.Graph):
def __init__(self, dataframe_report, which_graph: str, association_data):
self.set_style(["graph_base.mplstyle"])
Expand Down Expand Up @@ -207,6 +211,8 @@ def value_to_color(val):
if color_min == color_max:
return palette[-1]
else:
if val == CORRELATION_ERROR:
return palette[(n_colors - 1)]
val_position = float((val - color_min)) / (color_max - color_min) # position of value in the input range, relative to the length of the input range
val_position = min(max(val_position, 0), 1) # bound the position betwen 0 and 1
# LOG IT
Expand Down Expand Up @@ -234,6 +240,9 @@ def value_to_size(val):
else:
if val == 0:
return 0.0
# TODO: Better/more intuitive display of correlation errors
if val == CORRELATION_ERROR:
return 0.0
val_position = (val - size_min) * 0.999 / (size_max - size_min) + 0.001 # position of value in the input range, relative to the length of the input range
val_position = min(max(val_position, 0), 1) # bound the position betwen 0 and 1
# LOG IT
Expand Down

0 comments on commit 7dd8988

Please sign in to comment.