Skip to content

Commit

Permalink
rewrote show all column vis logic and frontend integration to avoid t…
Browse files Browse the repository at this point in the history
…raitlet error
  • Loading branch information
dorisjlee committed Apr 17, 2021
1 parent 4894fc4 commit c872e44
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lux/action/enhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def enhance(ldf):
"long_description": f"Enhance adds an additional attribute as the color to break down the {intended_attrs} distribution",
}
# if there are too many column attributes, return don't generate Enhance recommendations
elif len(attr_specs) > 2:
else:
recommendation = {"action": "Enhance"}
recommendation["collection"] = []
return recommendation
Expand Down
2 changes: 1 addition & 1 deletion lux/action/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def add_filter(ldf):
filter_values = []
output = []
# if fltr is specified, create visualizations where data is filtered by all values of the fltr's categorical variable
column_spec = utils.get_attrs_specs(ldf.current_vis[0].intent)
column_spec = utils.get_attrs_specs(ldf._intent)
column_spec_attr = list(map(lambda x: x.attribute, column_spec))
if len(filters) == 1:
# get unique values for all categorical values specified and creates corresponding filters
Expand Down
24 changes: 9 additions & 15 deletions lux/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def __init__(self, *args, **kw):
self.pre_aggregated = None
self._type_override = {}
warnings.formatwarning = lux.warning_format
self.all_column = False

@property
def _constructor(self):
Expand Down Expand Up @@ -346,19 +345,11 @@ def _append_rec(self, rec_infolist, recommendations: Dict):
rec_infolist.append(recommendations)

def show_all_column_vis(self):
from lux.processor.Compiler import Compiler

quantitative_columns = [i for i in self.data_type if i != "quantitative"]
curr_vis = VisList([i for i in self.columns], self)
if len(curr_vis) > 0:
Compiler.determine_encoding(self, curr_vis[0])
if (
curr_vis[0]._inferred_intent != []
and self._intent == []
and (len(quantitative_columns) == 2 or len(quantitative_columns) == 3)
):
self.current_vis = curr_vis
self.all_column = True
if(self.intent==[] or self.intent is None):
vis = Vis(list(self.columns), self)
if vis.mark != "":
vis._all_column = True
self.current_vis = VisList([vis])

def maintain_recs(self, is_series="DataFrame"):
# `rec_df` is the dataframe to generate the recommendations on
Expand Down Expand Up @@ -670,7 +661,6 @@ def render_widget(self, renderer: str = "altair", input_current_vis=""):
recommendations=widgetJSON["recommendation"],
intent=LuxDataFrame.intent_to_string(self._intent),
message=self._message.to_html(),
allColumn=self.all_column,
)

@staticmethod
Expand Down Expand Up @@ -716,6 +706,10 @@ def current_vis_to_JSON(vlist, input_current_vis=""):
current_vis_spec = vlist[0].to_code(language=lux.config.plotting_backend, prettyOutput=False)
elif numVC > 1:
pass
if vlist[0]._all_column:
current_vis_spec["allcols"] = True
else:
current_vis_spec["allcols"] = False
return current_vis_spec

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions lux/vis/Vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, intent, source=None, title="", score=0.0):
self._postbin = None
self.title = title
self.score = score
self._all_column = False
self.refresh_source(self._source)

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion lux/vislib/matplotlib/ScatterChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def initialize_chart(self):
if len(y_attr.attribute) > 25:
y_attr_abv = y_attr.attribute[:15] + "..." + y_attr.attribute[-10:]

df = self.data
df = self.data.dropna()

x_pts = df[x_attr.attribute]
y_pts = df[y_attr.attribute]
Expand Down
11 changes: 6 additions & 5 deletions tests/test_nan.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ def test_numeric_with_nan():
len(a.recommendation["Distribution"]) == 2
), "Testing a numeric columns with NaN, check that histograms are displayed"
assert "contains missing values" in a._message.to_html(), "Warning message for NaN displayed"
a = a.dropna()
a._ipython_display_()
assert (
len(a.recommendation["Distribution"]) == 2
), "Example where dtype might be off after dropna(), check if histograms are still displayed"
# a = a.dropna()
# # TODO: Needs to be explicitly called, possible problem with metadata prpogation
# a._ipython_display_()
# assert (
# len(a.recommendation["Distribution"]) == 2
# ), "Example where dtype might be off after dropna(), check if histograms are still displayed"
assert "" in a._message.to_html(), "No warning message for NaN should be displayed"

0 comments on commit c872e44

Please sign in to comment.