Repository: lux-org/lux (language: python)

Issue:
Better warning message for Vis and VisList
Issue: https://github.com/lux-org/lux/issues/116

Added edge case for "|" in string and list syntax
Added tests for above edge cases


Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index 993e5d90..82d57714 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,7 +14,7 @@ before_script:
    - psql -c "ALTER DATABASE postgres OWNER TO travis;"
    - psql -c "DROP schema public cascade;" -U postgres
    - psql -c "CREATE schema public;" -U postgres
-   - psql -c "CREATE DATABASE postgres_db;" -U postgres
+#   - psql -c "CREATE DATABASE postgres;" -U postgres
 # command to upload data to test environment SQL database and run tests
 script:
   - python lux/data/upload_car_data.py
diff --git a/lux/data/upload_car_data.py b/lux/data/upload_car_data.py
index af50bb66..d6f6958d 100644
--- a/lux/data/upload_car_data.py
+++ b/lux/data/upload_car_data.py
@@ -33,7 +33,6 @@
 target_url = "https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/car.csv"
 for line in urllib.request.urlopen(target_url):
     decoded = line.decode("utf-8")
-    print(decoded.split(","))
     if "Name,MilesPerGal,Cylinders" not in decoded:
         cur.execute(
             "INSERT INTO cars VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", decoded.split(",")


Test patch:
diff --git a/tests/test_compiler.py b/tests/test_compiler.py
index f2e3c10f..73732404 100644
--- a/tests/test_compiler.py
+++ b/tests/test_compiler.py
@@ -32,10 +32,10 @@ def test_underspecified_no_vis(global_var, test_recs):
     assert len(df.current_vis) == 0
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     test_recs(sql_df, no_vis_actions)
     assert len(sql_df.current_vis) == 0
@@ -60,10 +60,10 @@ def test_underspecified_single_vis(global_var, test_recs):
         assert attr.data_type == "quantitative"
     df.clear_intent()
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     sql_df.set_intent([lux.Clause(attribute="milespergal"), lux.Clause(attribute="weight")])
     test_recs(sql_df, one_vis_actions)
     assert len(sql_df.current_vis) == 1
@@ -114,10 +114,10 @@ def test_set_intent_as_vis(global_var, test_recs):
     df._repr_html_()
     test_recs(df, ["Enhance", "Filter", "Generalize"])
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     sql_df._repr_html_()
     vis = sql_df.recommendation["Correlation"][0]
     sql_df.intent = vis
@@ -150,17 +150,17 @@ def test_parse(global_var):
     vlst = VisList([lux.Clause("Origin=?"), lux.Clause("MilesPerGal")], df)
     assert len(vlst) == 3
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vlst = VisList([lux.Clause("origin=?"), lux.Clause(attribute="milespergal")], sql_df)
     assert len(vlst) == 3
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vlst = VisList([lux.Clause("origin=?"), lux.Clause("milespergal")], sql_df)
     assert len(vlst) == 3
 
@@ -183,10 +183,10 @@ def test_underspecified_vis_collection_zval(global_var):
     # vlst = VisList([lux.Clause(attribute = ["Origin","Cylinders"], filter_op="=",value="?"),lux.Clause(attribute = ["Horsepower"]),lux.Clause(attribute = "Weight")],df)
     # assert len(vlst) == 8
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vlst = VisList(
         [
             lux.Clause(attribute="origin", filter_op="=", value="?"),
@@ -224,10 +224,10 @@ def test_sort_bar(global_var):
     assert vis.mark == "bar"
     assert vis._inferred_intent[1].sort == "ascending"
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vis = Vis(
         [
             lux.Clause(attribute="acceleration", data_model="measure", data_type="quantitative"),
@@ -238,10 +238,10 @@ def test_sort_bar(global_var):
     assert vis.mark == "bar"
     assert vis._inferred_intent[1].sort == ""
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vis = Vis(
         [
             lux.Clause(attribute="acceleration", data_model="measure", data_type="quantitative"),
@@ -339,10 +339,10 @@ def test_autoencoding_scatter(global_var):
             ]
         )
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     visList = VisList(
         [lux.Clause(attribute="?"), lux.Clause(attribute="milespergal", channel="x")],
         sql_df,
@@ -394,10 +394,10 @@ def test_autoencoding_scatter():
         )
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vis = Vis([lux.Clause(attribute="milespergal"), lux.Clause(attribute="weight")], sql_df)
     check_attribute_on_channel(vis, "milespergal", "x")
     check_attribute_on_channel(vis, "weight", "y")
@@ -449,10 +449,10 @@ def test_autoencoding_histogram(global_var):
 
     # No channel specified
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vis = Vis([lux.Clause(attribute="milespergal", channel="y")], sql_df)
     check_attribute_on_channel(vis, "milespergal", "y")
 
@@ -502,10 +502,10 @@ def test_autoencoding_line_chart(global_var):
         )
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vis = Vis([lux.Clause(attribute="year"), lux.Clause(attribute="acceleration")], sql_df)
     check_attribute_on_channel(vis, "year", "x")
     check_attribute_on_channel(vis, "acceleration", "y")
@@ -558,10 +558,10 @@ def test_autoencoding_color_line_chart(global_var):
     check_attribute_on_channel(vis, "Origin", "color")
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     intent = [
         lux.Clause(attribute="year"),
         lux.Clause(attribute="acceleration"),
@@ -599,10 +599,10 @@ def test_autoencoding_color_scatter_chart(global_var):
     check_attribute_on_channel(vis, "Acceleration", "color")
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     vis = Vis(
         [
             lux.Clause(attribute="horsepower"),
@@ -653,10 +653,10 @@ def test_populate_options(global_var):
     )
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     sql_df.set_intent([lux.Clause(attribute="?"), lux.Clause(attribute="milespergal")])
     col_set = set()
     for specOptions in Compiler.populate_wildcard_options(sql_df._intent, sql_df)["attributes"]:
@@ -696,10 +696,10 @@ def test_remove_all_invalid(global_var):
     assert len(df.current_vis) == 0
 
     # test for sql executor
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = pd.DataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
     # with pytest.warns(UserWarning,match="duplicate attribute specified in the intent"):
     sql_df.set_intent(
         [
diff --git a/tests/test_sql_executor.py b/tests/test_sql_executor.py
index bee1698d..62cdcf3f 100644
--- a/tests/test_sql_executor.py
+++ b/tests/test_sql_executor.py
@@ -23,10 +23,10 @@
 
 
 def test_lazy_execution():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     intent = [
         lux.Clause(attribute="horsepower", aggregation="mean"),
@@ -40,10 +40,10 @@ def test_lazy_execution():
 
 
 def test_selection():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     intent = [
         lux.Clause(attribute=["horsepower", "weight", "acceleration"]),
@@ -55,10 +55,10 @@ def test_selection():
 
 
 def test_aggregation():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     intent = [
         lux.Clause(attribute="horsepower", aggregation="mean"),
@@ -89,10 +89,10 @@ def test_colored_bar_chart():
     from lux.vis.Vis import Vis
     from lux.vis.Vis import Clause
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     x_clause = Clause(attribute="milespergal", channel="x")
     y_clause = Clause(attribute="origin", channel="y")
@@ -112,10 +112,10 @@ def test_colored_line_chart():
     from lux.vis.Vis import Vis
     from lux.vis.Vis import Clause
 
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     x_clause = Clause(attribute="year", channel="x")
     y_clause = Clause(attribute="milespergal", channel="y")
@@ -133,10 +133,10 @@ def test_colored_line_chart():
 
 
 def test_filter():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     intent = [
         lux.Clause(attribute="horsepower"),
@@ -151,10 +151,10 @@ def test_filter():
 
 
 def test_inequalityfilter():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     vis = Vis(
         [
@@ -179,10 +179,10 @@ def test_inequalityfilter():
 
 
 def test_binning():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     vis = Vis([lux.Clause(attribute="horsepower")], sql_df)
     nbins = list(filter(lambda x: x.bin_size != 0, vis._inferred_intent))[0].bin_size
@@ -190,20 +190,20 @@ def test_binning():
 
 
 def test_record():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     vis = Vis([lux.Clause(attribute="cylinders")], sql_df)
     assert len(vis.data) == len(sql_df.unique_values["cylinders"])
 
 
 def test_filter_aggregation_fillzero_aligned():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     intent = [
         lux.Clause(attribute="cylinders"),
@@ -217,10 +217,10 @@ def test_filter_aggregation_fillzero_aligned():
 
 
 def test_exclude_attribute():
-    connection = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
+    connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
     sql_df = lux.LuxDataFrame()
     lux.config.set_SQL_connection(connection)
-    sql_df.set_SQL_table("car")
+    sql_df.set_SQL_table("cars")
 
     intent = [lux.Clause("?", exclude=["name", "year"]), lux.Clause("horsepower")]
     vislist = VisList(intent, sql_df)