Skip to content

Commit

Permalink
Add config parameters for Pandas Fallback (#233)
Browse files Browse the repository at this point in the history
* add series equality and value counts test

* black formatting

* fix old value counts test instead

* add configs for pandas fallbacks

* run black

* turn off fallback option for tests; fixed interestingness bug causing failed test

* black

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>
  • Loading branch information
westernguy2 and dorisjlee committed Jan 16, 2021
1 parent 23e4a79 commit 3ea3db1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
43 changes: 43 additions & 0 deletions lux/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self):
self._heatmap_flag = True
self._topk = 15
self._sort = "descending"
self._pandas_fallback = True
self._interestingness_fallback = True

@property
def topk(self):
Expand Down Expand Up @@ -80,6 +82,47 @@ def sort(self, flag: Union[str]):
stacklevel=2,
)

@property
def pandas_fallback(self):
return self._pandas_fallback

@pandas_fallback.setter
def pandas_fallback(self, fallback: bool) -> None:
"""
Parameters
----------
fallback : bool
If an error occurs, whether or not to raise an exception or fallback to default Pandas.
"""
if type(fallback) == bool:
self._pandas_fallback = fallback
else:
warnings.warn(
"The flag for Pandas fallback must be a boolean.",
stacklevel=2,
)

@property
def interestingness_fallback(self):
return self._interestingness_fallback

@interestingness_fallback.setter
def interestingness_fallback(self, fallback: bool) -> None:
"""
Parameters
----------
fallback : bool
If an error occurs while calculating interestingness, whether or not
to raise an exception or fallback to default Pandas.
"""
if type(fallback) == bool:
self._interestingness_fallback = fallback
else:
warnings.warn(
"The flag for interestingness fallback must be a boolean.",
stacklevel=2,
)

@property
def sampling_cap(self):
"""
Expand Down
19 changes: 11 additions & 8 deletions lux/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,17 @@ def on_button_clicked(b):
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
warnings.warn(
"\nUnexpected error in rendering Lux widget and recommendations. "
"Falling back to Pandas display.\n"
"Please report the following issue on Github: https://github.com/lux-org/lux/issues \n",
stacklevel=2,
)
warnings.warn(traceback.format_exc())
display(self.display_pandas())
if lux.config.pandas_fallback:
warnings.warn(
"\nUnexpected error in rendering Lux widget and recommendations. "
"Falling back to Pandas display.\n"
"Please report the following issue on Github: https://github.com/lux-org/lux/issues \n",
stacklevel=2,
)
warnings.warn(traceback.format_exc())
display(self.display_pandas())
else:
raise

def display_pandas(self):
return self.to_pandas()
Expand Down
12 changes: 7 additions & 5 deletions lux/interestingness/interestingness.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,12 @@ def interestingness(vis: Vis, ldf: LuxDataFrame) -> int:
else:
return -1
except:
# Supress interestingness related issues
warnings.warn(f"An error occurred when computing interestingness for: {vis}")
return -1
if lux.config.interestingness_fallback:
# Supress interestingness related issues
warnings.warn(f"An error occurred when computing interestingness for: {vis}")
return -1
else:
raise


def get_filtered_size(filter_specs, ldf):
Expand Down Expand Up @@ -339,6 +342,7 @@ def monotonicity(vis: Vis, attr_specs: list, ignore_identity: bool = True) -> in

if ignore_identity and msr1 == msr2: # remove if measures are the same
return -1
vis._vis_data = vis.data.dropna()
v_x = vis.data[msr1]
v_y = vis.data[msr2]

Expand All @@ -356,5 +360,3 @@ def monotonicity(vis: Vis, attr_specs: list, ignore_identity: bool = True) -> in
return -1
else:
return score
# import scipy.stats
# return abs(scipy.stats.pearsonr(v_x,v_y)[0])
3 changes: 3 additions & 0 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

import lux

lux.config.interestingness_fallback = False
lux.config.pandas_fallback = False
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def change_color_make_transparent_add_title(chart):
def test_sampling_flag_config():
df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/airbnb_nyc.csv")
df._repr_html_()
assert df.recommendation["Correlation"][0].data.shape[0] == 30000
assert df.recommendation["Correlation"][0].data.shape[0] < 48895
lux.config.sampling = False
df = df.copy()
df._repr_html_()
Expand All @@ -232,7 +232,7 @@ def test_heatmap_flag_config():
assert df.recommendation["Correlation"][0]._postbin
lux.config.heatmap = False
df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/airbnb_nyc.csv")
df = df.copy()
df._repr_html_()
assert not df.recommendation["Correlation"][0]._postbin
lux.config.heatmap = True

Expand Down

0 comments on commit 3ea3db1

Please sign in to comment.