Skip to content

Commit

Permalink
bugfix vary filter case
Browse files Browse the repository at this point in the history
  • Loading branch information
dorisjlee committed Jun 18, 2020
1 parent 7a46ba8 commit e79e24d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lux/action/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,18 @@ def filter(ldf):
columnSpec = utils.getAttrsSpecs(ldf.viewCollection[0].specLst)
columnSpecAttr = map(lambda x: x.attribute,columnSpec)
if len(filters) > 0:
completedFilters = []
#get unique values for all categorical values specified and creates corresponding filters
for row in filters:
if row.attribute not in completedFilters:
uniqueValues = ldf.uniqueValues[row.attribute]
filterValues.append(row.value)
#creates new data objects with new filters
for i in range(0, len(uniqueValues)):
if uniqueValues[i] not in filterValues:
newSpec = columnSpec.copy()
newFilter = lux.Spec(attribute = row.attribute, value = uniqueValues[i])
newSpec.append(newFilter)
tempView = View(newSpec)
completedFilters.append(row.attribute)
output.append(tempView)
uniqueValues = ldf.uniqueValues[row.attribute]
filterValues.append(row.value)
#creates new data objects with new filters
for val in uniqueValues:
if val not in filterValues:
newSpec = columnSpec.copy()
newFilter = lux.Spec(attribute = row.attribute, value = val)
newSpec.append(newFilter)
tempView = View(newSpec)
output.append(tempView)
else: #if no existing filters, create filters using unique values from all categorical variables in the dataset
categoricalVars = []
for col in list(ldf.columns):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .context import lux
import pytest
import pandas as pd

from lux.view.View import View
def test_vary_filter_val():
df = pd.read_csv("lux/data/olympic.csv")
view = View(["Height","SportType=Ball"])
view = view.load(df)
df.setContextAsView(view)
df.showMore()
assert len(df.recommendation["Filter"]) == len(df["SportType"].unique())-1

0 comments on commit e79e24d

Please sign in to comment.