diff --git a/lux/action/enhance.py b/lux/action/enhance.py index be3cd290..0f469543 100644 --- a/lux/action/enhance.py +++ b/lux/action/enhance.py @@ -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 diff --git a/lux/action/filter.py b/lux/action/filter.py index 44b1019a..5b6c2f1e 100644 --- a/lux/action/filter.py +++ b/lux/action/filter.py @@ -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 diff --git a/lux/core/frame.py b/lux/core/frame.py index 8d291b9c..0c56fb77 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -344,6 +344,13 @@ def _append_rec(self, rec_infolist, recommendations: Dict): if recommendations["collection"] is not None and len(recommendations["collection"]) > 0: rec_infolist.append(recommendations) + def show_all_column_vis(self): + 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 # check to see if globally defined actions have been registered/removed @@ -418,9 +425,11 @@ def maintain_recs(self, is_series="DataFrame"): if len(vlist) > 0: rec_df._recommendation[action_type] = vlist rec_df._rec_info = rec_infolist + rec_df.show_all_column_vis() self._widget = rec_df.render_widget() # re-render widget for the current dataframe if previous rec is not recomputed elif show_prev: + rec_df.show_all_column_vis() self._widget = rec_df.render_widget() self._recs_fresh = True @@ -697,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 diff --git a/lux/vis/Vis.py b/lux/vis/Vis.py index c1c7dfbe..aa2afed1 100644 --- a/lux/vis/Vis.py +++ b/lux/vis/Vis.py @@ -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): diff --git a/lux/vislib/matplotlib/ScatterChart.py b/lux/vislib/matplotlib/ScatterChart.py index 6829edc9..66dc8297 100644 --- a/lux/vislib/matplotlib/ScatterChart.py +++ b/lux/vislib/matplotlib/ScatterChart.py @@ -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] diff --git a/tests/test_nan.py b/tests/test_nan.py index 29efcb72..13ca88e9 100644 --- a/tests/test_nan.py +++ b/tests/test_nan.py @@ -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" diff --git a/tests/test_vis.py b/tests/test_vis.py index 15c75017..8f49d292 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -547,3 +547,39 @@ def test_matplotlib_heatmap_flag_config(): assert not df.recommendation["Correlation"][0]._postbin lux.config.heatmap = True lux.config.plotting_backend = "vegalite" + + +def test_all_column_current_vis(): + df = pd.read_csv( + "https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt", + delimiter=r"\s+", + parse_dates=[[0, 1, 2]], + header=None, + ) + df.columns = ["Date", "Temp"] + df._ipython_display_() + assert df.current_vis != None + + +def test_all_column_current_vis_filter(): + df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/car.csv") + df["Year"] = pd.to_datetime(df["Year"], format="%Y") + two_col_df = df[["Year", "Displacement"]] + two_col_df._ipython_display_() + assert two_col_df.current_vis != None + assert two_col_df.current_vis[0]._all_column + three_col_df = df[["Year", "Displacement", "Origin"]] + three_col_df._ipython_display_() + assert three_col_df.current_vis != None + assert three_col_df.current_vis[0]._all_column + + +def test_intent_override_all_column(): + df = pytest.car_df + df = df[["Year", "Displacement"]] + df.intent = ["Year"] + df._ipython_display_() + current_vis_code = df.current_vis[0].to_altair() + assert ( + "y = alt.Y('Record', type= 'quantitative', title='Number of Records'" in current_vis_code + ), "All column not overriden by intent"