Skip to content

Commit

Permalink
Updated Interestingness Tests (#133)
Browse files Browse the repository at this point in the history
* add black

* update cars dataset and tests

* Delete old dataset

* Updated Interestingness Tests

Updated tests to use the newly updated cars dataset

* switch to local cars reference

Co-authored-by: Kunal Agarwal <kagarwal2@berkeley.edu>
Co-authored-by: Kunal Agarwal <32151899+westernguy2@users.noreply.github.com>
Co-authored-by: 19thyneb <thyne.boonmark@gmail.com>
Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>
  • Loading branch information
5 people committed Nov 4, 2020
1 parent 4eb2bb1 commit 9311224
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 432 deletions.
786 changes: 393 additions & 393 deletions lux/data/car.csv

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def test_sort_bar():


def test_specified_vis_collection():
url = "https://github.com/lux-org/lux-datasets/blob/master/data/cars.csv?raw=true"
df = pd.read_csv(url)
df = pd.read_csv("lux/data/car.csv")
df["Year"] = pd.to_datetime(
df["Year"], format="%Y"
) # change pandas dtype for the column "Year" to datetype
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_period_to_altair():

exported_code = df.recommendation["Filter"][2].to_Altair()

assert "Year = 1971" in exported_code
assert "Year = 1972" in exported_code


def test_refresh_inplace():
Expand Down
18 changes: 9 additions & 9 deletions tests/test_interestingness.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def test_interestingness_1_0_0():
if int(vis._inferred_intent[2].value) == 8:
rank1 = f
if int(vis._inferred_intent[2].value) == 6:
rank2 = f
if "1972" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
rank3 = f
rank3 = f
if "ford" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
rank2 = f
assert rank1 < rank2 and rank1 < rank3 and rank2 < rank3


Expand Down Expand Up @@ -112,7 +112,7 @@ def test_interestingness_0_1_0():
rank1 = f
if str(df.recommendation["Filter"][f]._inferred_intent[2].value) == "Europe":
rank2 = f
if "1971" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
if "1970" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
rank3 = f
assert rank1 < rank2 and rank1 < rank3 and rank2 < rank3

Expand Down Expand Up @@ -151,11 +151,11 @@ def test_interestingness_1_1_0():
if len(vis.get_attr_by_attr_name("Cylinders")) > 0:
if int(vis._inferred_intent[2].value) == 6:
rank1 = f
if int(vis._inferred_intent[2].value) == 5:
rank3 = f
if int(vis._inferred_intent[2].value) == 8:
rank2 = f
if len(vis.get_attr_by_attr_name("Origin")) > 0:
if str(vis._inferred_intent[2].value) == "Europe":
rank2 = f
rank3 = f
assert rank1 < rank2 and rank1 < rank3 and rank2 < rank3

# check that top recommended generalize graph score is not none
Expand Down Expand Up @@ -261,9 +261,9 @@ def test_interestingness_0_2_0():
for f in range(0, len(df.recommendation["Filter"])):
if "1973" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
rank1 = f
if "1976" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
if "ford" in str(df.recommendation["Filter"][f]._inferred_intent[2].value):
rank2 = f
if str(df.recommendation["Filter"][f]._inferred_intent[2].value) == "Europe":
if str(df.recommendation["Filter"][f]._inferred_intent[2].value) == "USA":
rank3 = f
assert rank1 < rank2 and rank1 < rank3 and rank2 < rank3

Expand Down
4 changes: 2 additions & 2 deletions tests/test_maintainence.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def test_recs_inplace_operation():
df = pd.read_csv("lux/data/car.csv")
df._repr_html_()
assert df._recs_fresh == True, "Failed to maintain recommendation after display df"
assert len(df.recommendation["Occurrence"]) == 3
assert len(df.recommendation["Occurrence"]) == 4
df.drop(columns=["Name"], inplace=True)
assert "Name" not in df.columns, "Failed to perform `drop` operation in-place"
assert (
df._recs_fresh == False
), "Failed to maintain recommendation after in-place Pandas operation"
df._repr_html_()
assert len(df.recommendation["Occurrence"]) == 2
assert len(df.recommendation["Occurrence"]) == 3
assert df._recs_fresh == True, "Failed to maintain recommendation after display df"
42 changes: 17 additions & 25 deletions tests/test_pandas_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def test_rename3():
"col7",
"col8",
"col9",
"col10",
]
df._repr_html_()
assert list(df.recommendation.keys()) == [
Expand All @@ -119,7 +120,7 @@ def test_rename3():
"Occurrence",
"Temporal",
]
assert len(df.cardinality) == 9
assert len(df.cardinality) == 10
assert "col2" in list(df.cardinality.keys())


Expand Down Expand Up @@ -194,7 +195,7 @@ def test_query():
"Occurrence",
"Temporal",
]
assert len(new_df.cardinality) == 9
assert len(new_df.cardinality) == 10


def test_pop():
Expand All @@ -208,7 +209,7 @@ def test_pop():
"Occurrence",
"Temporal",
]
assert len(df.cardinality) == 8
assert len(df.cardinality) == 9


def test_transform():
Expand All @@ -217,7 +218,7 @@ def test_transform():
new_df = df.iloc[:, 1:].groupby("Origin").transform(sum)
new_df._repr_html_()
assert list(new_df.recommendation.keys()) == ["Correlation", "Occurrence"]
assert len(new_df.cardinality) == 6
assert len(new_df.cardinality) == 7


def test_get_group():
Expand All @@ -232,7 +233,7 @@ def test_get_group():
"Occurrence",
"Temporal",
]
assert len(new_df.cardinality) == 9
assert len(new_df.cardinality) == 10


def test_applymap():
Expand All @@ -247,13 +248,11 @@ def test_applymap():
"Occurrence",
"Temporal",
]
assert len(df.cardinality) == 9
assert len(df.cardinality) == 10


def test_strcat():
df = pd.read_csv(
"https://github.com/lux-org/lux-datasets/blob/master/data/cars.csv?raw=true"
)
df = pd.read_csv("lux/data/car.csv")
df["Year"] = pd.to_datetime(df["Year"], format="%Y")
df["combined"] = df["Origin"].str.cat(df["Brand"], sep=", ")
df._repr_html_()
Expand All @@ -267,9 +266,7 @@ def test_strcat():


def test_named_agg():
df = pd.read_csv(
"https://github.com/lux-org/lux-datasets/blob/master/data/cars.csv?raw=true"
)
df = pd.read_csv("lux/data/car.csv")
df["Year"] = pd.to_datetime(df["Year"], format="%Y")
new_df = df.groupby("Brand").agg(
avg_weight=("Weight", "mean"),
Expand All @@ -292,7 +289,7 @@ def test_change_dtype():
"Occurrence",
"Temporal",
]
assert len(df.data_type_lookup) == 9
assert len(df.data_type_lookup) == 10


def test_get_dummies():
Expand All @@ -306,7 +303,7 @@ def test_get_dummies():
"Occurrence",
"Temporal",
]
assert len(new_df.data_type_lookup) == 310
assert len(new_df.data_type_lookup) == 339


def test_drop():
Expand All @@ -321,7 +318,7 @@ def test_drop():
"Occurrence",
"Temporal",
]
assert len(new_df2.cardinality) == 6
assert len(new_df2.cardinality) == 7


def test_merge():
Expand All @@ -336,7 +333,7 @@ def test_merge():
"Occurrence",
"Temporal",
] # TODO once bug is fixed
assert len(new_df2.cardinality) == 10
assert len(new_df2.cardinality) == 11


def test_prefix():
Expand All @@ -350,14 +347,12 @@ def test_prefix():
"Occurrence",
"Temporal",
]
assert len(new_df.cardinality) == 9
assert len(new_df.cardinality) == 10
assert new_df.cardinality["1_Name"] == 300


def test_loc():
df = pd.read_csv(
"https://github.com/lux-org/lux-datasets/blob/master/data/cars.csv?raw=true"
)
df = pd.read_csv("lux/data/car.csv")
df["Year"] = pd.to_datetime(df["Year"], format="%Y")
new_df = df.loc[:, "Displacement":"Origin"]
new_df._repr_html_()
Expand Down Expand Up @@ -388,9 +383,7 @@ def test_loc():


def test_iloc():
df = pd.read_csv(
"https://github.com/lux-org/lux-datasets/blob/master/data/cars.csv?raw=true"
)
df = pd.read_csv("lux/data/car.csv")
df["Year"] = pd.to_datetime(df["Year"], format="%Y")
new_df = df.iloc[:, 3:9]
new_df._repr_html_()
Expand Down Expand Up @@ -563,8 +556,7 @@ def test_value_counts():


def test_str_replace():
url = "https://github.com/lux-org/lux-datasets/blob/master/data/cars.csv?raw=true"
df = pd.read_csv(url)
df = pd.read_csv("lux/data/car.csv")
df._repr_html_() # compute metadata
assert df.cardinality is not None
series = df["Brand"].str.replace("chevrolet", "chevy")
Expand Down

0 comments on commit 9311224

Please sign in to comment.