Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to SQL Executor Example Notebook #193

Merged
merged 128 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
308d99c
Merging Recent SQL Executor changes
19thyneb Oct 15, 2020
daa9a0d
Fix to Validator
19thyneb Oct 16, 2020
804b0dc
Fix Bug with Widget Rendering
19thyneb Oct 17, 2020
676f3e0
Added Number of Observations to MetaData, Fixed Interestingness issue…
19thyneb Oct 19, 2020
8763df9
Re-added Licensing Headers
19thyneb Oct 19, 2020
c2b0b46
Adding Recent frame.py changes
19thyneb Oct 19, 2020
1b08461
Adjusted SQL Executor Tests
19thyneb Oct 19, 2020
38c5e7e
Update Frame with new Action Registering
19thyneb Oct 22, 2020
14d2f90
Resolving Conflicts in frame.py
19thyneb Oct 22, 2020
78d8e10
Merge branch 'sql-engine' into Database-Executor
thyneb19 Oct 22, 2020
d783b4c
Commenting out local SQL Executor tests
19thyneb Oct 22, 2020
c03e001
Merge branch 'Database-Executor' of https://github.com/thyneb19/lux i…
19thyneb Oct 22, 2020
8f0e643
Update correlation.py
dorisjlee Oct 22, 2020
d365d52
Update frame.py
dorisjlee Oct 22, 2020
74ed59c
bugfix: "number of remaining bars" text overcounts for colored bar ch…
dorisjlee Oct 22, 2020
7da2992
Fixing Code Format
19thyneb Oct 22, 2020
f1b7c8b
Cleaning up Pandas Executor imports
19thyneb Oct 22, 2020
d97f0e4
Fix Validation Bug
19thyneb Oct 22, 2020
582b370
Changed metadata variable name
19thyneb Oct 23, 2020
16ded3a
Adding support for setting intent on front end (#112)
cjachekang Oct 23, 2020
554c71f
Merge remote-tracking branch 'upstream/sql-engine' into Database-Exec…
19thyneb Oct 23, 2020
b825c51
Make default_display a global setting (#121)
caitlynachen Oct 25, 2020
d65687a
Added script to generate Postgresql database
19thyneb Oct 25, 2020
7243b2f
Update upload_car_data.py
19thyneb Oct 25, 2020
2add76f
Updated script name in travis.yml
19thyneb Oct 25, 2020
cf74beb
Removed unnecessary import from travis.yml
19thyneb Oct 25, 2020
14d52b8
Added psycopg2 to requirements.txt
19thyneb Oct 25, 2020
379517d
Creating Postgres test database in travis
19thyneb Oct 25, 2020
a72f236
Fixed directory issue
19thyneb Oct 25, 2020
e947fd6
Updated SQL Executor Tests
19thyneb Oct 26, 2020
0fb9421
Update requirements.txt (#128)
dorisjlee Oct 29, 2020
a06d968
replaced _exportedVisIdxs --> _selectedVisIdxs
dorisjlee Oct 29, 2020
f740e89
bugfix: plot config error when current_vis is None
dorisjlee Oct 30, 2020
1234009
Added sql_executor example notebook, minor bug fix
19thyneb Oct 31, 2020
6a20c47
Add LuxSeries Implementation (#122)
westernguy2 Nov 2, 2020
f986c76
add black to travis (#127)
jinimukh Nov 2, 2020
4eb2bb1
fix doc failing from black format
dorisjlee Nov 2, 2020
a5eff98
Cleaned SQL Executor Example Notebook
19thyneb Nov 2, 2020
5e18fd8
Update custom action reference to executor
19thyneb Nov 2, 2020
9311224
Updated Interestingness Tests (#133)
thyneb19 Nov 4, 2020
cb4c90f
fix broken link in docs
dorisjlee Nov 4, 2020
8029ac1
Updated Tests, Added benchmarking for SQL Executor
19thyneb Nov 6, 2020
bca1f0c
Merge remote-tracking branch 'upstream/master' into Database-Executor
19thyneb Nov 7, 2020
4046579
Merge with upstream branch, added preliminary benchmarking code
19thyneb Nov 7, 2020
9897d0e
Better warning message for Vis and VisList (#135)
cjachekang Nov 9, 2020
af0043a
Pandas rewrite Performance optimizations (#136)
dorisjlee Nov 11, 2020
907f215
Added 2D Binning functionality to SQL Executor
19thyneb Nov 15, 2020
603e3d7
Update README.md
dorisjlee Nov 15, 2020
852c6a1
Updated temporal detection and tests (#139)
jrdzha Nov 16, 2020
ea20833
Fix Inline comments breaking to new lines (#137)
jinimukh Nov 16, 2020
7430e01
Improve warning message when values specified as attributes (#143)
dorisjlee Nov 17, 2020
f5be470
Better warning message for Vis and VisList (#146)
cjachekang Nov 18, 2020
da79415
Updated docs for JupyterLab (#148)
cjachekang Nov 19, 2020
21e20cf
Global shared variable in test (#144) (#149)
piyushg9794 Nov 19, 2020
2b24129
Merge remote-tracking branch 'upstream/master' into Database-Executor
19thyneb Nov 19, 2020
21ba332
Updated 2D Binning Functionality
19thyneb Nov 19, 2020
d8e3a7c
documentation for custom actions (#134)
caitlynachen Nov 20, 2020
d2a19da
Patch failing test (#134)
dorisjlee Nov 21, 2020
5f8c200
Patch failing test (#134)
dorisjlee Nov 21, 2020
f7fe32d
Patch failing test (#134)
dorisjlee Nov 21, 2020
b7ac30c
Added Heatmap generation to SQL Executor, Bug fix in PandasExecutor
19thyneb Nov 22, 2020
ad32db7
Updated Code Formatting with Black
19thyneb Nov 22, 2020
8948538
Merge branch 'sql-engine' into Database-Executor
thyneb19 Nov 22, 2020
6f032f2
Update Requirements to include psycopg2
19thyneb Nov 22, 2020
06dbf14
Merge branch 'Database-Executor' of https://github.com/thyneb19/lux i…
19thyneb Nov 22, 2020
aff131f
Update upload_car_data.py
19thyneb Nov 22, 2020
0ca0d98
Update Compiler tests to use correct test DB
19thyneb Nov 22, 2020
776489f
Removed Benchmarking Code
19thyneb Nov 22, 2020
7d00742
Fixing Black Formatting
19thyneb Nov 22, 2020
3543b12
Add Toggle button for LuxSeries (#153)
westernguy2 Nov 23, 2020
974079d
Reformat Warnings Labels (#151)
caitlynachen Nov 23, 2020
b1bb129
Make plot_config a global variable (#152)
jinimukh Nov 23, 2020
873629c
Patch documentation (#134)
dorisjlee Nov 23, 2020
8991206
code cleanup
dorisjlee Nov 25, 2020
7101df1
Moved Executor Parameters to Global Config
19thyneb Nov 25, 2020
4e3ecb7
Black formatting
19thyneb Nov 25, 2020
8e42fb8
Fix issue with read_json and add tests for different file types (#156)
westernguy2 Nov 26, 2020
3a8d9f9
Improved warning message stack trace for unexpected error (#145)
dorisjlee Nov 27, 2020
a48cdc7
Moved table_name parameter to frame.py. Removed executor_type parameter
19thyneb Nov 27, 2020
bccd61a
Fixed reference to table_name parameter
19thyneb Nov 28, 2020
770a30d
bug fix patching #146 (#159)
dorisjlee Nov 28, 2020
b3e33fa
Ensure that recommendation and current_vis properties are accessible …
dorisjlee Nov 28, 2020
8149e72
bugfix erased `name` dtype in LuxSeries (#140)
dorisjlee Nov 28, 2020
5794718
Adjusted Functions to Set SQL Connection
19thyneb Nov 29, 2020
fb61c27
Merge branch 'master' into Database-Executor
19thyneb Nov 29, 2020
43a70c1
Update Makefile and pyproject.toml (#160)
jinimukh Nov 29, 2020
0c6443a
Update README.md
dorisjlee Nov 29, 2020
727315b
Update SQLExecutor name parameter
19thyneb Nov 29, 2020
52e6be4
Merging master branch with sql engine. Moving executor parameters to …
19thyneb Nov 29, 2020
2cc5b10
Merge branch 'master' into Database-Executor
19thyneb Nov 29, 2020
10e9ea1
Merge remote-tracking branch 'upstream/master' into Database-Executor
19thyneb Nov 29, 2020
b3e1e88
Parameter Bug Fix
19thyneb Nov 29, 2020
d774a41
Reference Fix in Warning
19thyneb Nov 29, 2020
9747848
Black Formatting
19thyneb Nov 29, 2020
fbafb96
Merge branch 'sql-engine' into Database-Executor
19thyneb Nov 29, 2020
ecfb434
Black formatting
19thyneb Nov 29, 2020
1034e2b
bump version number and requirements
dorisjlee Nov 30, 2020
705cd05
PATCH v0.2.1.1
dorisjlee Nov 30, 2020
47ece2b
Merge remote-tracking branch 'upstream/master'
19thyneb Nov 30, 2020
3e68db3
Fix Executor Reference
19thyneb Nov 30, 2020
3a5473e
Update frame.py
dorisjlee Dec 2, 2020
68d1600
Moved set functions to global config
19thyneb Dec 2, 2020
b6a5e99
Cleaned up executor imports, Fixed issue in AltairRenderer
19thyneb Dec 3, 2020
9a1748c
Black formatting
19thyneb Dec 3, 2020
3b316d9
Moved Executor Parameters to Global Config (#157)
thyneb19 Dec 3, 2020
868156d
save_as_html feature (#170)
dorisjlee Dec 5, 2020
476f0ac
Updating documentation for lux-widget v0.1.2 release (#176)
cjachekang Dec 9, 2020
91f965f
Fix bug caused by `groupby.agg` on column with many unique values (#174)
westernguy2 Dec 9, 2020
dd3818a
Update save_as_html docs (#170)
dorisjlee Dec 10, 2020
227f150
Update README
dorisjlee Dec 10, 2020
b7635c0
Update README.md
dorisjlee Dec 19, 2020
cb22f5c
Merge remote-tracking branch 'upstream/master'
19thyneb Dec 20, 2020
5223a11
Fixed Index Issue in Pandas Executor
19thyneb Dec 20, 2020
e08460b
Making Lux more robust with missing values and NaN (#179) (#180)
dorisjlee Dec 21, 2020
96a38e7
bump version and requirement
dorisjlee Dec 21, 2020
ad89594
Added tests for set_index functions
19thyneb Dec 21, 2020
4718c05
Black formatting
19thyneb Dec 21, 2020
2a7d4b2
Merge remote-tracking branch 'upstream/master'
19thyneb Dec 22, 2020
269c062
Update Pandas Executor to handle NA values
19thyneb Dec 22, 2020
79b381a
Merge branch 'master' into Database-Executor
19thyneb Dec 27, 2020
fd93cd4
Update to Config, and Compiler/Interestingness Tests
19thyneb Dec 27, 2020
7324e29
Merge branch 'sql-engine' into Database-Executor
19thyneb Dec 27, 2020
674d828
Black formatting
19thyneb Dec 27, 2020
2931442
Update Requirements.txt
19thyneb Dec 27, 2020
7cc9626
Update SQL Executor Documentation
19thyneb Jan 4, 2021
1d517d8
Updated SQLExecutor Example Notebook
19thyneb Jan 4, 2021
f5a358c
Merge branch 'sql-engine' into Database-Executor
19thyneb Jan 4, 2021
3a27d76
Black Formatting
19thyneb Jan 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 70 additions & 8 deletions examples/Postgres_Executor_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You can upload the car dataset to a local postgres database using the upload_car_data.py script in the lux/data folder. You will need to update the name of the database and the login credentials in that file."
"This demo requires that you have a local posgres SQL database already set up. If you have not done this yet, you can download the PostgreSQL installer here: https://www.postgresql.org/download/. Follow the instructions to get your database environment setup."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you have your PostgreSQL environment set up, you can upload the example [car dataset](https://github.com/lux-org/lux-datasets/blob/master/data/car.csv) to your database using the script found [here](https://github.com/thyneb19/lux/blob/Database-Executor/lux/data/upload_car_data.py)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To connect Lux to your PostgreSQL database, you will first need to create a psycopg2 connection. After that you will be able to specify this connection in the Lux config, and connect a Lux DataFrame to a table as shown below."
]
},
{
Expand All @@ -26,11 +40,18 @@
"import psycopg2\n",
"import pandas as pd\n",
"\n",
"connection = psycopg2.connect(\"host=localhost dbname=postgres_db user=postgres password=lux\")\n",
"connection = psycopg2.connect(\"host=localhost dbname=postgres user=postgres password=lux\")\n",
"\n",
"sql_df = lux.LuxDataFrame()\n",
"sql_df.set_SQL_connection(connection, \"car\")\n",
"sql_df"
"lux.config.set_SQL_connection(connection)\n",
"sql_df.set_SQL_table(\"cars\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once the Lux Dataframe has been connected to a database table, the parameters necessary to run Lux' recommendation system will automatically be populated."
]
},
{
Expand All @@ -39,19 +60,51 @@
"metadata": {},
"outputs": [],
"source": [
"#you can view the variable datatypes here\n",
"sql_df.data_type"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that the connection between your DataFrame and your database has been established, you can leverage all of Lux's visual recommendation tools. For a more in-depth look at Lux's functions, check out the main repository [here](https://github.com/lux-org/lux)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#call the Lux DataFrame to view general variable distributions and relationships.\n",
"#You will see that the DataFrame contains the columns of your database table, but is otherwise empty.\n",
"#Data is processed as much as possible on the database end, and is only brought in locally when needed to create visualizations.\n",
"sql_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#you can specify intents just the same as the default Lux system\n",
"from lux.vis import Clause\n",
"\n",
"#here we specify that we are interested in a graph containing the variables 'milespergal' and 'cylinders'\n",
"#we also specify that we want to apply a filter 'horsepower > 150' to this visualization\n",
"sql_df.set_intent([\"milespergal\", 'cylinders', Clause(attribute =\"horsepower\", filter_op=\">\", value=150)])\n",
"sql_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also use Lux's Vis package to generate visualizations without having to pull in or process data from your database manually. Instead, you can specify visualization channels and create graphs as shown below."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -61,12 +114,21 @@
"from lux.vis.Vis import Vis\n",
"from lux.vis.Vis import Clause\n",
"\n",
"x_clause = Clause(attribute = \"milespergal\", channel = \"x\")\n",
"y_clause = Clause(attribute = \"weight\", channel = \"y\")\n",
"#Create a new Lux Clause for each variable you want to use in your graph\n",
"#Specify how you want to use the variable in the graph via the channel parameter.\n",
"#The channel parameter will specify whether or not a variable is used on the x or y axis, or used to color datapoints\n",
"x_clause = Clause(attribute = \"acceleration\", channel = \"x\")\n",
"y_clause = Clause(attribute = \"milespergal\", channel = \"y\")\n",
"color_clause = Clause(attribute = 'cylinders', channel = \"color\")\n",
"filter_clause = Clause(attribute =\"horsepower\", filter_op=\">\", value=150)\n",
"\n",
"new_vis = Vis([x_clause, y_clause, color_clause])\n",
"#you can also create filters on your data using Lux Clauses like so\n",
"filter_clause = Clause(attribute =\"origin\", filter_op=\"=\", value='USA')\n",
"\n",
"#to create the graph, create a Lux Vis object with the list of your Clauses as the parameter\n",
"new_vis = Vis([x_clause, y_clause, color_clause, filter_clause])\n",
"\n",
"#to fetch the data necessary for the graph, use the refresh_source function.\n",
"#the refresh_source function takes in a Lux DataFrame, in this case you can specify the one connected to your database table\n",
"new_vis.refresh_source(sql_df)\n",
"new_vis"
]
Expand Down
21 changes: 12 additions & 9 deletions lux/data/upload_car_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import psycopg2
import csv

conn = psycopg2.connect("host=localhost dbname=postgres_db user=postgres password=lux")
conn = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
cur = conn.cursor()
cur.execute(
"""
DROP TABLE IF EXISTS car
DROP TABLE IF EXISTS cars
"""
)
# create car table in postgres database
cur.execute(
"""
CREATE TABLE car(
CREATE TABLE cars(
name text,
milespergal numeric,
cylinders integer,
Expand All @@ -28,11 +28,14 @@
)

# open car.csv and read data into database
with open("lux/data/car.csv", "r") as f:
reader = csv.reader(f)
next(reader) # Skip the header row.
i = 0
for row in reader:
cur.execute("INSERT INTO car VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", row)
import urllib.request

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(",")
)
conn.commit()
Loading