From 74da4f44d88a5b285c1b3598f7f3e32608bd30df Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 10:34:57 -0800 Subject: [PATCH 01/36] rec series --- lux/core/series.py | 13 +++++++++++++ tests/test_interestingness.py | 1 - tests/test_vis.py | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lux/core/series.py b/lux/core/series.py index 27750710..0ced1312 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -202,3 +202,16 @@ def on_button_clicked(b): warnings.warn(traceback.format_exc()) display(self.to_pandas()) return "" + + @property + def recommendation(self): + from lux.core.frame import LuxDataFrame + + if self.name is None: + self.name = " " + ldf = LuxDataFrame(self) + + if self._recommendation is not None and self._recommendation == {}: + ldf.maintain_metadata() + ldf.maintain_recs() + return ldf._recommendation diff --git a/tests/test_interestingness.py b/tests/test_interestingness.py index dd5812b0..a5498907 100644 --- a/tests/test_interestingness.py +++ b/tests/test_interestingness.py @@ -102,7 +102,6 @@ def test_interestingness_0_1_0(global_var): ): rank3 = f assert rank1 < rank2 and rank1 < rank3 and rank2 < rank3 - # check that top recommended filter graph score is not none and that ordering makes intuitive sense assert interestingness(df.recommendation["Filter"][0], df) != None diff --git a/tests/test_vis.py b/tests/test_vis.py index b5af7c9b..3c592859 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -497,3 +497,17 @@ def test_matplotlib_heatmap_flag_config(): assert not df.recommendation["Correlation"][0]._postbin lux.config.heatmap = True lux.config.plotting_backend = "vegalite" + + +def test_series_recommendation(): + lux.config.plotting_backend = "matplotlib" + df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") + df.plot_config = None + df = df["YearsAtCompany"] / df["TotalWorkingYears"] + assert len(df.recommendation["Distribution"]) > 0 + + lux.config.plotting_backend = "vegalite" + df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") + df.plot_config = None + df = df["YearsAtCompany"] / df["TotalWorkingYears"] + assert len(df.recommendation["Distribution"]) > 0 From 8548ab2842f41912bf17ba75b399ca213a1e267e Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 13:41:28 -0800 Subject: [PATCH 02/36] rec --- tests/test_series.py | 17 +++++++++++++++++ tests/test_vis.py | 14 -------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/test_series.py b/tests/test_series.py index 65a0f00a..a4dc2f71 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -65,3 +65,20 @@ def test_print_iterrow(global_var): print(row) break assert len(w) == 0, "Warning displayed when printing iterrow" + + +def test_unnamed_column(): + lux.config.plotting_backend = "matplotlib" + df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") + df.plot_config = None + df = df["YearsAtCompany"] / df["TotalWorkingYears"] + df.__repr__() + axis_title = "Series (binned)" + exported_code_str = df.recommendation["Distribution"][0].to_matplotlib_code() + assert axis_title in exported_code_str + + lux.config.plotting_backend = "vegalite" + df = df["YearsAtCompany"] / df["TotalWorkingYears"] + df.__repr__() + exported_code_str = df.recommendation["Distribution"][0].to_Altair() + assert axis_title in exported_code_str diff --git a/tests/test_vis.py b/tests/test_vis.py index 3c592859..b5af7c9b 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -497,17 +497,3 @@ def test_matplotlib_heatmap_flag_config(): assert not df.recommendation["Correlation"][0]._postbin lux.config.heatmap = True lux.config.plotting_backend = "vegalite" - - -def test_series_recommendation(): - lux.config.plotting_backend = "matplotlib" - df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") - df.plot_config = None - df = df["YearsAtCompany"] / df["TotalWorkingYears"] - assert len(df.recommendation["Distribution"]) > 0 - - lux.config.plotting_backend = "vegalite" - df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") - df.plot_config = None - df = df["YearsAtCompany"] / df["TotalWorkingYears"] - assert len(df.recommendation["Distribution"]) > 0 From c7151254cd938d459616874061229fa35a19eb4d Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 20:14:07 -0800 Subject: [PATCH 03/36] add changes back --- lux/vislib/altair/Histogram.py | 16 ++++++++++------ lux/vislib/matplotlib/Histogram.py | 7 +++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lux/vislib/altair/Histogram.py b/lux/vislib/altair/Histogram.py index 60c2d999..0144e529 100644 --- a/lux/vislib/altair/Histogram.py +++ b/lux/vislib/altair/Histogram.py @@ -55,6 +55,10 @@ def initialize_chart(self): markbar = x_range / plot_range * 12 self.data = AltairChart.sanitize_dataframe(self.data) + + axis_title = f"{msr_attr_abv} (binned)" + if msr_attr.attribute == " ": + axis_title = "Series (binned)" if measure.channel == "x": chart = ( alt.Chart(self.data) @@ -62,10 +66,10 @@ def initialize_chart(self): .encode( alt.X( str(msr_attr.attribute), - title=f"{msr_attr.attribute} (binned)", + title=axis_title, bin=alt.Bin(binned=True), type=msr_attr.data_type, - axis=alt.Axis(labelOverlap=True, title=f"{msr_attr_abv} (binned)"), + axis=alt.Axis(labelOverlap=True, title=axis_title), scale=alt.Scale(domain=(x_min, x_max)), ), alt.Y("Number of Records", type="quantitative"), @@ -79,9 +83,9 @@ def initialize_chart(self): x=alt.X("Number of Records", type="quantitative"), y=alt.Y( str(msr_attr.attribute), - title=f"{msr_attr.attribute} (binned)", + title=axis_title, bin=alt.Bin(binned=True), - axis=alt.Axis(labelOverlap=True, title=f"{msr_attr_abv} (binned)"), + axis=alt.Axis(labelOverlap=True, title=axis_title), scale=alt.Scale(domain=(x_min, x_max)), ), ) @@ -96,14 +100,14 @@ def initialize_chart(self): if measure.channel == "x": self.code += f""" chart = alt.Chart(visData).mark_bar(size={markbar}).encode( - alt.X('{msr_attr.attribute}', title='{msr_attr.attribute} (binned)',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{msr_attr_abv} (binned)'), scale=alt.Scale(domain=({x_min}, {x_max}))), + alt.X('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))), alt.Y("Number of Records", type="quantitative") ) """ elif measure.channel == "y": self.code += f""" chart = alt.Chart(visData).mark_bar(size={markbar}).encode( - alt.Y('{msr_attr.attribute}', title='{msr_attr.attribute} (binned)',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{msr_attr_abv} (binned)'), scale=alt.Scale(domain=({x_min}, {x_max}))), + alt.Y('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))), alt.X("Number of Records", type="quantitative") ) """ diff --git a/lux/vislib/matplotlib/Histogram.py b/lux/vislib/matplotlib/Histogram.py index 826ceee2..c4ef8f2b 100644 --- a/lux/vislib/matplotlib/Histogram.py +++ b/lux/vislib/matplotlib/Histogram.py @@ -59,12 +59,15 @@ def initialize_chart(self): x_label = "" y_label = "" + axis_title = f"{msr_attr_abv} (binned)" + if msr_attr_abv == " ": + axis_title = "Series (binned)" if measure.channel == "x": - x_label = f"{msr_attr.attribute} (binned)" + x_label = axis_title y_label = "Number of Records" elif measure.channel == "y": x_label = "Number of Records" - y_label = f"{msr_attr.attribute} (binned)" + y_label = axis_title self.ax.set_xlabel(x_label) self.ax.set_ylabel(y_label) From 68aadb35af58095c0e41eec09a6df46e9f04c6f9 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 20:45:59 -0800 Subject: [PATCH 04/36] fix tests --- examples/Long ColNames.ipynb | 450 +++++++++++++++++++++++++++++++++++ examples/issue175test.csv | 25 ++ tests/test_series.py | 38 +-- 3 files changed, 494 insertions(+), 19 deletions(-) create mode 100644 examples/Long ColNames.ipynb create mode 100644 examples/issue175test.csv diff --git a/examples/Long ColNames.ipynb b/examples/Long ColNames.ipynb new file mode 100644 index 00000000..7e3c08f9 --- /dev/null +++ b/examples/Long ColNames.ipynb @@ -0,0 +1,450 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/luxfor\n" + ] + } + ], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CONTRIBUTING.md codecov.yml pyproject.toml\r\n", + "LICENSE \u001b[34mdist\u001b[m\u001b[m/ requirements-dev.txt\r\n", + "MANIFEST.in \u001b[34mdoc\u001b[m\u001b[m/ requirements.txt\r\n", + "Makefile \u001b[34mexamples\u001b[m\u001b[m/ setup.cfg\r\n", + "README.md \u001b[34mlux\u001b[m\u001b[m/ setup.py\r\n", + "\u001b[34mbuild\u001b[m\u001b[m/ \u001b[34mlux_api.egg-info\u001b[m\u001b[m/ \u001b[34mtests\u001b[m\u001b[m/\r\n" + ] + } + ], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.read_csv(\"issue175test.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3894ebb087e64075a33c27bee131d3ac", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "94064bc205d24fe3812d231aa3f7fb83", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df\n", + "# df.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9358ab28eb9a4e648fecffbe69fe621f", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "adef35ed19ba490ab84ee6bef45a4601", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "\n", + "dataset = [{\"special.char\": 1.0, \"normal\": 2.0},{\"special.char\": 1.0, \"normal\": 2.0},]\n", + "df = pd.DataFrame(dataset)\n", + "\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'LuxWidget' object has no attribute '_selectedVisIdxs'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbookmarked_charts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexported\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mbookmarked_charts\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/anaconda3/envs/lux/lib/python3.8/site-packages/lux_api-0.2.1.1-py3.8.egg/lux/core/frame.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 140\u001b[0m \u001b[0;31m#####################\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__getattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 142\u001b[0;31m \u001b[0mret_value\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mLuxDataFrame\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 143\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexpire_metadata\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexpire_recs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5128\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5129\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5130\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5131\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5132\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/anaconda3/envs/lux/lib/python3.8/site-packages/lux_api-0.2.1.1-py3.8.egg/lux/core/frame.py\u001b[0m in \u001b[0;36mexported\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 524\u001b[0m )\n\u001b[1;32m 525\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 526\u001b[0;31m \u001b[0mexported_vis_lst\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_widget\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_selectedVisIdxs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 527\u001b[0m \u001b[0mexported_vis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 528\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexported_vis_lst\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'LuxWidget' object has no attribute '_selectedVisIdxs'" + ] + } + ], + "source": [ + "bookmarked_charts = df.exported\n", + "bookmarked_charts" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "75cc6b61c6604b118d3945fc14576a22", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "213af93e182f4bbd8329bf3564db74dc", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "203b8b0b3a5847ad975bae683fde68e4", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "eee37ab994f24c24b758310cd30a76af", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'measure': [],\n", + " 'dimension': ['Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities',\n", + " 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups']}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/issue175test.csv b/examples/issue175test.csv new file mode 100644 index 00000000..0a42146f --- /dev/null +++ b/examples/issue175test.csv @@ -0,0 +1,25 @@ +Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.,"The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups." +Evident,Evident +Not Evident,Not Evident +Somewhat Evident,Not Evident +Not Evident,Not Evident +Evident,Evident +Not Evident,Not Evident +Somewhat Evident,Somewhat Evident +Not Evident,Not Evident +Evident,Evident +Not Evident,Evident +Somewhat Evident,Evident +Not Evident,Evident +Evident,Evident +Not Evident,Evident +Somewhat Evident,Evident +Not Evident,Evident +Evident,Evident +Not Evident,Not Evident +Somewhat Evident,Somewhat Evident +Not Evident,Not Evident +Evident,Evident +Not Evident,Not Evident +Somewhat Evident,Somewhat Evident +Not Evident,Not Evident \ No newline at end of file diff --git a/tests/test_series.py b/tests/test_series.py index 9bdfa76a..8a34515f 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -67,25 +67,25 @@ def test_print_iterrow(global_var): assert len(w) == 0, "Warning displayed when printing iterrow" -def test_series_recommendation(): - df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") - df.plot_config = None - df = df["YearsAtCompany"] / df["TotalWorkingYears"] - assert len(df.recommendation["Distribution"]) > 0, "Recommendation property empty for LuxSeries" +# def test_series_recommendation(): +# df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") +# df.plot_config = None +# df = df["YearsAtCompany"] / df["TotalWorkingYears"] +# assert len(df.recommendation["Distribution"]) > 0, "Recommendation property empty for LuxSeries" -def test_unnamed_column(): - lux.config.plotting_backend = "matplotlib" - df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") - df.plot_config = None - df = df["YearsAtCompany"] / df["TotalWorkingYears"] - df.__repr__() - axis_title = "Series (binned)" - exported_code_str = df.recommendation["Distribution"][0].to_matplotlib_code() - assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" +# def test_unnamed_column(): +# lux.config.plotting_backend = "matplotlib" +# df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") +# df.plot_config = None +# series = df["YearsAtCompany"] / df["TotalWorkingYears"] +# series.__repr__() +# axis_title = "Series (binned)" +# exported_code_str = series.recommendation["Distribution"][0].to_matplotlib_code() +# assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" - lux.config.plotting_backend = "vegalite" - df = df["YearsAtCompany"] / df["TotalWorkingYears"] - df.__repr__() - exported_code_str = df.recommendation["Distribution"][0].to_Altair() - assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" +# lux.config.plotting_backend = "vegalite" +# series = df["YearsAtCompany"] / df["TotalWorkingYears"] +# series.__repr__() +# exported_code_str = series.recommendation["Distribution"][0].to_Altair() +# assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" From f3ee32d73ec073f9933b841d044f3227b10d382a Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 20:46:11 -0800 Subject: [PATCH 05/36] rm --- examples/Long ColNames.ipynb | 450 ----------------------------------- examples/issue175test.csv | 25 -- 2 files changed, 475 deletions(-) delete mode 100644 examples/Long ColNames.ipynb delete mode 100644 examples/issue175test.csv diff --git a/examples/Long ColNames.ipynb b/examples/Long ColNames.ipynb deleted file mode 100644 index 7e3c08f9..00000000 --- a/examples/Long ColNames.ipynb +++ /dev/null @@ -1,450 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/luxfor\n" - ] - } - ], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CONTRIBUTING.md codecov.yml pyproject.toml\r\n", - "LICENSE \u001b[34mdist\u001b[m\u001b[m/ requirements-dev.txt\r\n", - "MANIFEST.in \u001b[34mdoc\u001b[m\u001b[m/ requirements.txt\r\n", - "Makefile \u001b[34mexamples\u001b[m\u001b[m/ setup.cfg\r\n", - "README.md \u001b[34mlux\u001b[m\u001b[m/ setup.py\r\n", - "\u001b[34mbuild\u001b[m\u001b[m/ \u001b[34mlux_api.egg-info\u001b[m\u001b[m/ \u001b[34mtests\u001b[m\u001b[m/\r\n" - ] - } - ], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "df = pd.read_csv(\"issue175test.csv\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "3894ebb087e64075a33c27bee131d3ac", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "94064bc205d24fe3812d231aa3f7fb83", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df\n", - "# df.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9358ab28eb9a4e648fecffbe69fe621f", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "adef35ed19ba490ab84ee6bef45a4601", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import numpy as np\n", - "\n", - "dataset = [{\"special.char\": 1.0, \"normal\": 2.0},{\"special.char\": 1.0, \"normal\": 2.0},]\n", - "df = pd.DataFrame(dataset)\n", - "\n", - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "ename": "AttributeError", - "evalue": "'LuxWidget' object has no attribute '_selectedVisIdxs'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbookmarked_charts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexported\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mbookmarked_charts\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/anaconda3/envs/lux/lib/python3.8/site-packages/lux_api-0.2.1.1-py3.8.egg/lux/core/frame.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 140\u001b[0m \u001b[0;31m#####################\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__getattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 142\u001b[0;31m \u001b[0mret_value\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mLuxDataFrame\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 143\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexpire_metadata\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexpire_recs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.local/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5128\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5129\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5130\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5131\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5132\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/opt/anaconda3/envs/lux/lib/python3.8/site-packages/lux_api-0.2.1.1-py3.8.egg/lux/core/frame.py\u001b[0m in \u001b[0;36mexported\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 524\u001b[0m )\n\u001b[1;32m 525\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 526\u001b[0;31m \u001b[0mexported_vis_lst\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_widget\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_selectedVisIdxs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 527\u001b[0m \u001b[0mexported_vis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 528\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mexported_vis_lst\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mAttributeError\u001b[0m: 'LuxWidget' object has no attribute '_selectedVisIdxs'" - ] - } - ], - "source": [ - "bookmarked_charts = df.exported\n", - "bookmarked_charts" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "" - ], - "text/plain": [ - "alt.Chart(...)" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "75cc6b61c6604b118d3945fc14576a22", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "213af93e182f4bbd8329bf3564db74dc", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "203b8b0b3a5847ad975bae683fde68e4", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "eee37ab994f24c24b758310cd30a76af", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'measure': [],\n", - " 'dimension': ['Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities',\n", - " 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups']}" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.3" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/examples/issue175test.csv b/examples/issue175test.csv deleted file mode 100644 index 0a42146f..00000000 --- a/examples/issue175test.csv +++ /dev/null @@ -1,25 +0,0 @@ -Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.,"The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups." -Evident,Evident -Not Evident,Not Evident -Somewhat Evident,Not Evident -Not Evident,Not Evident -Evident,Evident -Not Evident,Not Evident -Somewhat Evident,Somewhat Evident -Not Evident,Not Evident -Evident,Evident -Not Evident,Evident -Somewhat Evident,Evident -Not Evident,Evident -Evident,Evident -Not Evident,Evident -Somewhat Evident,Evident -Not Evident,Evident -Evident,Evident -Not Evident,Not Evident -Somewhat Evident,Somewhat Evident -Not Evident,Not Evident -Evident,Evident -Not Evident,Not Evident -Somewhat Evident,Somewhat Evident -Not Evident,Not Evident \ No newline at end of file From 00a716572e32b2100658e0d91751361cb1549f9f Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 22:12:24 -0800 Subject: [PATCH 06/36] change --- tests/test_series.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/test_series.py b/tests/test_series.py index 8a34515f..5412aa96 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -67,25 +67,25 @@ def test_print_iterrow(global_var): assert len(w) == 0, "Warning displayed when printing iterrow" -# def test_series_recommendation(): -# df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") -# df.plot_config = None -# df = df["YearsAtCompany"] / df["TotalWorkingYears"] -# assert len(df.recommendation["Distribution"]) > 0, "Recommendation property empty for LuxSeries" +def test_series_recommendation(): + df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") + df.plot_config = None + df = df["YearsAtCompany"] / df["TotalWorkingYears"] + assert len(df.recommendation["Distribution"]) > 0, "Recommendation property empty for LuxSeries" -# def test_unnamed_column(): -# lux.config.plotting_backend = "matplotlib" -# df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") -# df.plot_config = None -# series = df["YearsAtCompany"] / df["TotalWorkingYears"] -# series.__repr__() -# axis_title = "Series (binned)" -# exported_code_str = series.recommendation["Distribution"][0].to_matplotlib_code() -# assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" +def test_unnamed_column(): + lux.config.plotting_backend = "matplotlib" + df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") + df.plot_config = None + series = df["YearsAtCompany"] / df["TotalWorkingYears"] + series.__repr__() + axis_title = "Series (binned)" + exported_code_str = series.recommendation["Distribution"][0].to_matplotlib_code() + assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" -# lux.config.plotting_backend = "vegalite" -# series = df["YearsAtCompany"] / df["TotalWorkingYears"] -# series.__repr__() -# exported_code_str = series.recommendation["Distribution"][0].to_Altair() -# assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" + lux.config.plotting_backend = "vegalite" + series = df["YearsAtCompany"] / df["TotalWorkingYears"] + series.__repr__() + exported_code_str = series.recommendation["Distribution"][0].to_Altair() + assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" From 5192fb5659bcccdad48857b3ca9a47a76fed9a90 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 16 Feb 2021 22:20:03 -0800 Subject: [PATCH 07/36] set plotting_style --- tests/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_series.py b/tests/test_series.py index 5412aa96..010b08b7 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -77,7 +77,7 @@ def test_series_recommendation(): def test_unnamed_column(): lux.config.plotting_backend = "matplotlib" df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/employee.csv") - df.plot_config = None + lux.config.plotting_style = None series = df["YearsAtCompany"] / df["TotalWorkingYears"] series.__repr__() axis_title = "Series (binned)" From 3d529e0ecb841246b7faa1d02d2abc195c1679ef Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Fri, 19 Feb 2021 15:27:46 -0800 Subject: [PATCH 08/36] nice --- lux/core/series.py | 3 +-- tests/test_series.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index 17209320..2c40080d 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -74,7 +74,6 @@ def __init__(self, *args, **kw): self.__dict__[attr] = self._default_metadata[attr]() else: self.__dict__[attr] = None - self._widget = None @property def _constructor(self): @@ -293,4 +292,4 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: stacklevel=2, ) return [] - + diff --git a/tests/test_series.py b/tests/test_series.py index e943ebf9..9162531c 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -88,5 +88,4 @@ def test_unnamed_column(): series = df["YearsAtCompany"] / df["TotalWorkingYears"] series.__repr__() exported_code_str = series.recommendation["Distribution"][0].to_Altair() - assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" - \ No newline at end of file + assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" \ No newline at end of file From 9a9224792c0ff571a3aed79d5e53733f1e52ac4b Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Fri, 19 Feb 2021 15:27:56 -0800 Subject: [PATCH 09/36] black --- lux/core/series.py | 2 +- tests/test_series.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index 2c40080d..ad48c95d 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -27,6 +27,7 @@ from lux.utils.utils import check_import_lux_widget from typing import Dict, Union, List, Callable + class LuxSeries(pd.Series): """ A subclass of pd.Series that supports all 1-D Series operations @@ -292,4 +293,3 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: stacklevel=2, ) return [] - diff --git a/tests/test_series.py b/tests/test_series.py index 9162531c..010b08b7 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -88,4 +88,4 @@ def test_unnamed_column(): series = df["YearsAtCompany"] / df["TotalWorkingYears"] series.__repr__() exported_code_str = series.recommendation["Distribution"][0].to_Altair() - assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" \ No newline at end of file + assert axis_title in exported_code_str, "Unnamed column should have 'Series' as placeholder" From 9b6ccc0e37bd5a9115581996d25b32633a97f111 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Fri, 19 Feb 2021 15:30:03 -0800 Subject: [PATCH 10/36] rm --- lux/core/series.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index ad48c95d..4965b15b 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -19,12 +19,7 @@ import numpy as np from lux.history.history import History from lux.utils.message import Message - - from lux.vis.VisList import VisList -from lux.history.history import History -from lux.utils.message import Message -from lux.utils.utils import check_import_lux_widget from typing import Dict, Union, List, Callable From f5c9efdce40b54079e3886e26ee32a4e8ac482a2 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Fri, 19 Feb 2021 15:38:36 -0800 Subject: [PATCH 11/36] change rec --- lux/core/series.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index 4965b15b..1dde0886 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -160,7 +160,6 @@ def __repr__(self): ldf._widget.observe(ldf.set_intent_on_click, names="selectedIntentIndex") self._widget = ldf._widget - self._recommendation = ldf.recommendation if len(ldf.recommendation) > 0: # box = widgets.Box(layout=widgets.Layout(display='inline')) @@ -210,7 +209,15 @@ def on_button_clicked(b): @property def recommendation(self): - return self._recommendation + from lux.core.frame import LuxDataFrame + + if self.name is None: + self.name = " " + ldf = LuxDataFrame(self) + + ldf.maintain_metadata() + ldf.maintain_recs() + return ldf._recommendation @property def exported(self) -> Union[Dict[str, VisList], VisList]: From ec40700837ef64b0693e629b4038d867ddad1167 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Tue, 23 Feb 2021 17:14:14 -0800 Subject: [PATCH 12/36] reuse export --- lux/core/series.py | 73 ++++++++-------------------------------------- 1 file changed, 12 insertions(+), 61 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index 1dde0886..adda372c 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -115,6 +115,7 @@ def __repr__(self): if self.name is None: self.name = " " ldf = LuxDataFrame(self) + self._ldf = ldf try: # Ignore recommendations when Series a results of: @@ -160,6 +161,7 @@ def __repr__(self): ldf._widget.observe(ldf.set_intent_on_click, names="selectedIntentIndex") self._widget = ldf._widget + self._recommendation = ldf._recommendation if len(ldf.recommendation) > 0: # box = widgets.Box(layout=widgets.Layout(display='inline')) @@ -211,13 +213,15 @@ def on_button_clicked(b): def recommendation(self): from lux.core.frame import LuxDataFrame - if self.name is None: - self.name = " " - ldf = LuxDataFrame(self) + if self._recommendation is not None and self._recommendation == {}: + if self.name is None: + self.name = " " + ldf = LuxDataFrame(self) - ldf.maintain_metadata() - ldf.maintain_recs() - return ldf._recommendation + ldf.maintain_metadata() + ldf.maintain_recs() + self._recommendation = ldf._recommendation + return self._recommendation @property def exported(self) -> Union[Dict[str, VisList], VisList]: @@ -240,58 +244,5 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: When all the exported vis is from the same tab, return a VisList of selected visualizations. -> VisList(v1, v2...) When the exported vis is from the different tabs, return a dictionary with the action name as key and selected visualizations in the VisList. -> {"Enhance": VisList(v1, v2...), "Filter": VisList(v5, v7...), ..} """ - if self._widget is None: - warnings.warn( - "\nNo widget attached to the dataframe." - "Please assign dataframe to an output variable.\n" - "See more: https://lux-api.readthedocs.io/en/latest/source/guide/FAQ.html#troubleshooting-tips", - stacklevel=2, - ) - return [] - exported_vis_lst = self._widget._selectedVisIdxs - exported_vis = [] - if exported_vis_lst == {}: - if self._saved_export: - return self._saved_export - warnings.warn( - "\nNo visualization selected to export.\n" - "See more: https://lux-api.readthedocs.io/en/latest/source/guide/FAQ.html#troubleshooting-tips", - stacklevel=2, - ) - return [] - if len(exported_vis_lst) == 1 and "currentVis" in exported_vis_lst: - return self.current_vis - elif len(exported_vis_lst) > 1: - exported_vis = {} - if "currentVis" in exported_vis_lst: - exported_vis["Current Vis"] = self.current_vis - for export_action in exported_vis_lst: - if export_action != "currentVis": - exported_vis[export_action] = VisList( - list( - map( - self._recommendation[export_action].__getitem__, - exported_vis_lst[export_action], - ) - ) - ) - return exported_vis - elif len(exported_vis_lst) == 1 and ("currentVis" not in exported_vis_lst): - export_action = list(exported_vis_lst.keys())[0] - exported_vis = VisList( - list( - map( - self._recommendation[export_action].__getitem__, - exported_vis_lst[export_action], - ) - ) - ) - self._saved_export = exported_vis - return exported_vis - else: - warnings.warn( - "\nNo visualization selected to export.\n" - "See more: https://lux-api.readthedocs.io/en/latest/source/guide/FAQ.html#troubleshooting-tips", - stacklevel=2, - ) - return [] + return self._ldf.exported + From ed22f8a0feb797dbc5908e2363b89add2b27c542 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Thu, 25 Mar 2021 19:57:26 -0700 Subject: [PATCH 13/36] remove altair --- lux/core/series.py | 1 - lux/vislib/matplotlib/BarChart.py | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index adda372c..f7d2e36f 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -245,4 +245,3 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: When the exported vis is from the different tabs, return a dictionary with the action name as key and selected visualizations in the VisList. -> {"Enhance": VisList(v1, v2...), "Filter": VisList(v5, v7...), ..} """ return self._ldf.exported - diff --git a/lux/vislib/matplotlib/BarChart.py b/lux/vislib/matplotlib/BarChart.py index aefab752..ccba7858 100644 --- a/lux/vislib/matplotlib/BarChart.py +++ b/lux/vislib/matplotlib/BarChart.py @@ -62,7 +62,6 @@ def initialize_chart(self): bar_attr = x_attr.attribute k = 10 - self._topkcode = "" n_bars = len(self.data.iloc[:, 0].unique()) if n_bars > k: # Truncating to only top k remaining_bars = n_bars - k @@ -79,16 +78,6 @@ def initialize_chart(self): color="#ff8e04", ) - self._topkcode = f"""text = alt.Chart(visData).mark_text( - x=155, - y=142, - align="right", - color = "#ff8e04", - fontSize = 11, - text=f"+ {remaining_bars} more ..." - ) - chart = chart + text\n""" - df = pd.DataFrame(self.data) bars = df[bar_attr].apply(lambda x: str(x)) From e6a0ee8a77d3b330e7e8ca1f4bac20f8f8f5c0cc Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Thu, 25 Mar 2021 20:10:11 -0700 Subject: [PATCH 14/36] nice --- examples/demo.ipynb | 428 ++++++++++++++++++++++++++ lux/vislib/matplotlib/ScatterChart.py | 2 +- 2 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 examples/demo.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb new file mode 100644 index 00000000..137202fb --- /dev/null +++ b/examples/demo.ipynb @@ -0,0 +1,428 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "e83e2b0a78d74002a12a9e2dea974f9b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "fe2eef09bee64d80b79692903e0c1969", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'time' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['time'] = pd.to_datetime(df['time'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If time is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'time':'quantitative'})\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d970da4f9bff4698a0a1b3b288fd9b60", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "113fdc4d24684a7ebccd5e3adc8f11d6", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='time')\n", + "pdf" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "809cddcb05624200addd58bfe6672b57", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "63297c8f8417457981837c8b834685ed", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv(\"../lux/data/car.csv\")\n", + "df.set_intent([\"Horsepower\", \"Displacement\"])\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Distribution': []}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lux/vislib/matplotlib/ScatterChart.py b/lux/vislib/matplotlib/ScatterChart.py index cd605f93..b07ee53c 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 = pd.DataFrame(self.data) + df=self.data x_pts = df[x_attr.attribute] y_pts = df[y_attr.attribute] From e6b069cd6e675bd2df23584b23f28203b1964090 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Thu, 25 Mar 2021 20:10:34 -0700 Subject: [PATCH 15/36] rm --- examples/demo.ipynb | 428 -------------------------------------------- 1 file changed, 428 deletions(-) delete mode 100644 examples/demo.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb deleted file mode 100644 index 137202fb..00000000 --- a/examples/demo.ipynb +++ /dev/null @@ -1,428 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "e83e2b0a78d74002a12a9e2dea974f9b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "fe2eef09bee64d80b79692903e0c1969", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'time' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['time'] = pd.to_datetime(df['time'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If time is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'time':'quantitative'})\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "d970da4f9bff4698a0a1b3b288fd9b60", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "113fdc4d24684a7ebccd5e3adc8f11d6", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='time')\n", - "pdf" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "809cddcb05624200addd58bfe6672b57", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "63297c8f8417457981837c8b834685ed", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = pd.read_csv(\"../lux/data/car.csv\")\n", - "df.set_intent([\"Horsepower\", \"Displacement\"])\n", - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'Distribution': []}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.2" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From a03c0818f7926cba2d647f198772ddce39c91504 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Thu, 25 Mar 2021 20:13:21 -0700 Subject: [PATCH 16/36] fix --- lux/core/series.py | 109 +++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 57 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index f7d2e36f..82ffcd23 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -49,6 +49,7 @@ class LuxSeries(pd.Series): "_pandas_only", "pre_aggregated", "_type_override", + "name", ] _default_metadata = { @@ -104,23 +105,27 @@ def to_pandas(self) -> pd.Series: return lux.core.originalSeries(self, copy=False) - def __repr__(self): + def _ipython_display_(self): from IPython.display import display from IPython.display import clear_output import ipywidgets as widgets from lux.core.frame import LuxDataFrame series_repr = super(LuxSeries, self).__repr__() + + ldf = LuxDataFrame(self) + # Default column name 0 causes errors if self.name is None: - self.name = " " - ldf = LuxDataFrame(self) + ldf = ldf.rename(columns={0: " "}) self._ldf = ldf try: # Ignore recommendations when Series a results of: # 1) Values of the series are of dtype objects (df.dtypes) - is_dtype_series = all(isinstance(val, np.dtype) for val in self.values) + is_dtype_series = ( + all(isinstance(val, np.dtype) for val in self.values) and len(self.values) != 0 + ) # 2) Mixed type, often a result of a "row" acting as a series (df.iterrows, df.iloc[0]) # Tolerant for NaNs + 1 type mixed_dtype = len(set([type(val) for val in self.values])) > 2 @@ -128,25 +133,8 @@ def __repr__(self): print(series_repr) ldf._pandas_only = False else: - if self.index.nlevels >= 2: - warnings.warn( - "\nLux does not currently support series " - "with hierarchical indexes.\n" - "Please convert the series into a flat " - "table via `pandas.DataFrame.reset_index`.\n", - stacklevel=2, - ) - print(series_repr) - return "" - - if len(self) <= 0: - warnings.warn( - "\nLux can not operate on an empty series.\nPlease check your input again.\n", - stacklevel=2, - ) - print(series_repr) - return "" - ldf.maintain_metadata() + if not self.index.nlevels >= 2: + ldf.maintain_metadata() if lux.config.default_display == "lux": self._toggle_pandas_display = False @@ -154,7 +142,7 @@ def __repr__(self): self._toggle_pandas_display = True # df_to_display.maintain_recs() # compute the recommendations (TODO: This can be rendered in another thread in the background to populate self._widget) - ldf.maintain_recs() + ldf.maintain_recs(is_series="Series") # Observers(callback_function, listen_to_this_variable) ldf._widget.observe(ldf.remove_deleted_recs, names="deletedIndices") @@ -163,38 +151,31 @@ def __repr__(self): self._widget = ldf._widget self._recommendation = ldf._recommendation - if len(ldf.recommendation) > 0: - # box = widgets.Box(layout=widgets.Layout(display='inline')) - button = widgets.Button( - description="Toggle Pandas/Lux", - layout=widgets.Layout(width="140px", top="5px"), - ) - ldf.output = widgets.Output() - # box.children = [button,output] - # output.children = [button] - # display(box) - display(button, ldf.output) - - def on_button_clicked(b): - with ldf.output: - if b: - self._toggle_pandas_display = not self._toggle_pandas_display - clear_output() - if self._toggle_pandas_display: - print(series_repr) - else: - # b.layout.display = "none" - display(ldf._widget) - # b.layout.display = "inline-block" - - button.on_click(on_button_clicked) - on_button_clicked(None) - else: - warnings.warn( - "\nLux defaults to Pandas when there are no valid actions defined.", - stacklevel=2, - ) - print(series_repr) + # box = widgets.Box(layout=widgets.Layout(display='inline')) + button = widgets.Button( + description="Toggle Pandas/Lux", + layout=widgets.Layout(width="140px", top="5px"), + ) + ldf.output = widgets.Output() + # box.children = [button,output] + # output.children = [button] + # display(box) + display(button, ldf.output) + + def on_button_clicked(b): + with ldf.output: + if b: + self._toggle_pandas_display = not self._toggle_pandas_display + clear_output() + if self._toggle_pandas_display: + print(series_repr) + else: + # b.layout.display = "none" + display(ldf._widget) + # b.layout.display = "inline-block" + + button.on_click(on_button_clicked) + on_button_clicked(None) except (KeyboardInterrupt, SystemExit): raise @@ -207,7 +188,6 @@ def on_button_clicked(b): ) warnings.warn(traceback.format_exc()) display(self.to_pandas()) - return "" @property def recommendation(self): @@ -245,3 +225,18 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: When the exported vis is from the different tabs, return a dictionary with the action name as key and selected visualizations in the VisList. -> {"Enhance": VisList(v1, v2...), "Filter": VisList(v5, v7...), ..} """ return self._ldf.exported + + def groupby(self, *args, **kwargs): + history_flag = False + if "history" not in kwargs or ("history" in kwargs and kwargs["history"]): + history_flag = True + if "history" in kwargs: + del kwargs["history"] + groupby_obj = super(LuxSeries, self).groupby(*args, **kwargs) + for attr in self._metadata: + groupby_obj.__dict__[attr] = getattr(self, attr, None) + if history_flag: + groupby_obj._history = groupby_obj._history.copy() + groupby_obj._history.append_event("groupby", *args, **kwargs) + groupby_obj.pre_aggregated = True + return groupby_obj \ No newline at end of file From b5ccd58dbd4a5b4d8c04b72fdf75e5b4b363d559 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 29 Mar 2021 09:51:40 -0700 Subject: [PATCH 17/36] fix merge --- examples/demo.ipynb | 429 +++++++++++++++++++++++++++++ lux/vislib/matplotlib/BarChart.py | 2 +- lux/vislib/matplotlib/Heatmap.py | 2 +- lux/vislib/matplotlib/Histogram.py | 2 +- lux/vislib/matplotlib/LineChart.py | 2 +- 5 files changed, 433 insertions(+), 4 deletions(-) create mode 100644 examples/demo.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb new file mode 100644 index 00000000..d02e19b7 --- /dev/null +++ b/examples/demo.ipynb @@ -0,0 +1,429 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "57897c05208640d6b0754d22204b8390", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b7edba48d50c4508a2f343d2d041ba39", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'time' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['time'] = pd.to_datetime(df['time'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If time is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'time':'quantitative'})\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d970da4f9bff4698a0a1b3b288fd9b60", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "113fdc4d24684a7ebccd5e3adc8f11d6", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='time')\n", + "pdf" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:401: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n", + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/vislib/matplotlib/MatplotlibRenderer.py:94: UserWarning:Tight layout not applied. The bottom and top margins cannot be made large enough to accommodate all axes decorations. \n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9e633a410d824890b42fa67be3fa2121", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ea071fe537f94bf4a7e412a7443da60c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv(\"../lux/data/car.csv\")\n", + "df.set_intent([\"Horsepower\", \"Displacement\"])\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Distribution': []}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lux/vislib/matplotlib/BarChart.py b/lux/vislib/matplotlib/BarChart.py index ccba7858..bd602a0c 100644 --- a/lux/vislib/matplotlib/BarChart.py +++ b/lux/vislib/matplotlib/BarChart.py @@ -78,7 +78,7 @@ def initialize_chart(self): color="#ff8e04", ) - df = pd.DataFrame(self.data) + df=self.data bars = df[bar_attr].apply(lambda x: str(x)) measurements = df[measure_attr] diff --git a/lux/vislib/matplotlib/Heatmap.py b/lux/vislib/matplotlib/Heatmap.py index 3b2b2ab6..042c6246 100644 --- a/lux/vislib/matplotlib/Heatmap.py +++ b/lux/vislib/matplotlib/Heatmap.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 = pd.DataFrame(self.data) + df=self.data plot_code = "" color_attr = self.vis.get_attr_by_channel("color") diff --git a/lux/vislib/matplotlib/Histogram.py b/lux/vislib/matplotlib/Histogram.py index c4ef8f2b..a39fe59f 100644 --- a/lux/vislib/matplotlib/Histogram.py +++ b/lux/vislib/matplotlib/Histogram.py @@ -49,7 +49,7 @@ def initialize_chart(self): markbar = abs(x_max - x_min) / 12 - df = pd.DataFrame(self.data) + df=self.data bars = df[msr_attr.attribute] measurements = df["Number of Records"] diff --git a/lux/vislib/matplotlib/LineChart.py b/lux/vislib/matplotlib/LineChart.py index db805dde..a62231da 100644 --- a/lux/vislib/matplotlib/LineChart.py +++ b/lux/vislib/matplotlib/LineChart.py @@ -52,7 +52,7 @@ def initialize_chart(self): self.data = self.data.dropna(subset=[x_attr.attribute, y_attr.attribute]) - df = pd.DataFrame(self.data) + df=self.data x_pts = df[x_attr.attribute] y_pts = df[y_attr.attribute] From 70cf6336d7cc57ef57f898b3d058ca8f0c902ffb Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 29 Mar 2021 09:51:49 -0700 Subject: [PATCH 18/36] rm --- examples/demo.ipynb | 429 -------------------------------------------- 1 file changed, 429 deletions(-) delete mode 100644 examples/demo.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb deleted file mode 100644 index d02e19b7..00000000 --- a/examples/demo.ipynb +++ /dev/null @@ -1,429 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "57897c05208640d6b0754d22204b8390", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "b7edba48d50c4508a2f343d2d041ba39", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'time' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['time'] = pd.to_datetime(df['time'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If time is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'time':'quantitative'})\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "d970da4f9bff4698a0a1b3b288fd9b60", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "113fdc4d24684a7ebccd5e3adc8f11d6", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='time')\n", - "pdf" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:401: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n", - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/vislib/matplotlib/MatplotlibRenderer.py:94: UserWarning:Tight layout not applied. The bottom and top margins cannot be made large enough to accommodate all axes decorations. \n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9e633a410d824890b42fa67be3fa2121", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "ea071fe537f94bf4a7e412a7443da60c", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = pd.read_csv(\"../lux/data/car.csv\")\n", - "df.set_intent([\"Horsepower\", \"Displacement\"])\n", - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'Distribution': []}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.2" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From cf857009e49048c58d2f9cd9e3fd9b74d006de35 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 29 Mar 2021 13:44:42 -0700 Subject: [PATCH 19/36] black --- lux/core/series.py | 2 +- lux/vislib/matplotlib/BarChart.py | 2 +- lux/vislib/matplotlib/Heatmap.py | 2 +- lux/vislib/matplotlib/Histogram.py | 2 +- lux/vislib/matplotlib/LineChart.py | 2 +- lux/vislib/matplotlib/ScatterChart.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lux/core/series.py b/lux/core/series.py index 82ffcd23..a5e2defd 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -239,4 +239,4 @@ def groupby(self, *args, **kwargs): groupby_obj._history = groupby_obj._history.copy() groupby_obj._history.append_event("groupby", *args, **kwargs) groupby_obj.pre_aggregated = True - return groupby_obj \ No newline at end of file + return groupby_obj diff --git a/lux/vislib/matplotlib/BarChart.py b/lux/vislib/matplotlib/BarChart.py index bd602a0c..6f706f7d 100644 --- a/lux/vislib/matplotlib/BarChart.py +++ b/lux/vislib/matplotlib/BarChart.py @@ -78,7 +78,7 @@ def initialize_chart(self): color="#ff8e04", ) - df=self.data + df = self.data bars = df[bar_attr].apply(lambda x: str(x)) measurements = df[measure_attr] diff --git a/lux/vislib/matplotlib/Heatmap.py b/lux/vislib/matplotlib/Heatmap.py index 042c6246..c4f58b08 100644 --- a/lux/vislib/matplotlib/Heatmap.py +++ b/lux/vislib/matplotlib/Heatmap.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 plot_code = "" color_attr = self.vis.get_attr_by_channel("color") diff --git a/lux/vislib/matplotlib/Histogram.py b/lux/vislib/matplotlib/Histogram.py index a39fe59f..8aef0291 100644 --- a/lux/vislib/matplotlib/Histogram.py +++ b/lux/vislib/matplotlib/Histogram.py @@ -49,7 +49,7 @@ def initialize_chart(self): markbar = abs(x_max - x_min) / 12 - df=self.data + df = self.data bars = df[msr_attr.attribute] measurements = df["Number of Records"] diff --git a/lux/vislib/matplotlib/LineChart.py b/lux/vislib/matplotlib/LineChart.py index a62231da..b2fd9f11 100644 --- a/lux/vislib/matplotlib/LineChart.py +++ b/lux/vislib/matplotlib/LineChart.py @@ -52,7 +52,7 @@ def initialize_chart(self): self.data = self.data.dropna(subset=[x_attr.attribute, y_attr.attribute]) - df=self.data + df = self.data x_pts = df[x_attr.attribute] y_pts = df[y_attr.attribute] diff --git a/lux/vislib/matplotlib/ScatterChart.py b/lux/vislib/matplotlib/ScatterChart.py index b07ee53c..816ea2bf 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 x_pts = df[x_attr.attribute] y_pts = df[y_attr.attribute] From f063bf80df1db61c41c16c5b457cad967d2c21b7 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 31 Mar 2021 12:00:57 -0700 Subject: [PATCH 20/36] all column vis --- lux/core/frame.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lux/core/frame.py b/lux/core/frame.py index af47d77e..87c5a4c8 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -498,9 +498,13 @@ def maintain_recs(self, is_series="DataFrame"): if len(vlist) > 0: rec_df._recommendation[action_type] = vlist rec_df._rec_info = rec_infolist + if len(self.columns) == 2 or len(self.columns) == 3: + self.current_vis = VisList([i for i in self.columns], self) self._widget = rec_df.render_widget() # re-render widget for the current dataframe if previous rec is not recomputed elif show_prev: + if len(self.columns) == 2 or len(self.columns) == 3: + self.current_vis = VisList([i for i in self.columns], self) self._widget = rec_df.render_widget() self._recs_fresh = True From e32f8ae28221a8315f7899ea5d2942e34af5148b Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 31 Mar 2021 12:39:05 -0700 Subject: [PATCH 21/36] only quant --- lux/core/frame.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lux/core/frame.py b/lux/core/frame.py index 87c5a4c8..269265f1 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -498,12 +498,14 @@ def maintain_recs(self, is_series="DataFrame"): if len(vlist) > 0: rec_df._recommendation[action_type] = vlist rec_df._rec_info = rec_infolist - if len(self.columns) == 2 or len(self.columns) == 3: + quantitative_columns = [i for i in self.dtypes if i != 'O' and i != 'str'] + if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: self.current_vis = VisList([i for i in self.columns], self) self._widget = rec_df.render_widget() # re-render widget for the current dataframe if previous rec is not recomputed elif show_prev: - if len(self.columns) == 2 or len(self.columns) == 3: + quantitative_columns = [i for i in self.dtypes if i != 'O' and i != 'str'] + if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: self.current_vis = VisList([i for i in self.columns], self) self._widget = rec_df.render_widget() self._recs_fresh = True From 9e15b2cfa2d7238c6f8e8309733b013dc7b4ab9c Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 31 Mar 2021 13:04:12 -0700 Subject: [PATCH 22/36] rip --- lux/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lux/core/frame.py b/lux/core/frame.py index 269265f1..f281282f 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -498,7 +498,7 @@ def maintain_recs(self, is_series="DataFrame"): if len(vlist) > 0: rec_df._recommendation[action_type] = vlist rec_df._rec_info = rec_infolist - quantitative_columns = [i for i in self.dtypes if i != 'O' and i != 'str'] + quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: self.current_vis = VisList([i for i in self.columns], self) self._widget = rec_df.render_widget() From 36ef3ad923682f20d7962c77f6d381af3e51f6ba Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 31 Mar 2021 13:09:38 -0700 Subject: [PATCH 23/36] add tests --- tests/test_action.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_action.py b/tests/test_action.py index 5e22938c..bcc86cb9 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -274,3 +274,14 @@ def test_intent_retained(): df._ipython_display_() assert list(df.recommendation.keys()) == ["Enhance", "Filter"] + +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 + + df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}}) + df = df.melt(id_vars=["nPts"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name="type", value_name='t') + df._ipython_display_() + assert df.current_vis != None From 369113e036151df6af1e812cba1ca315db7f845f Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 31 Mar 2021 13:22:17 -0700 Subject: [PATCH 24/36] black --- lux/core/frame.py | 2 +- tests/test_action.py | 126 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 123 insertions(+), 5 deletions(-) diff --git a/lux/core/frame.py b/lux/core/frame.py index f281282f..b1f08053 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -504,7 +504,7 @@ def maintain_recs(self, is_series="DataFrame"): self._widget = rec_df.render_widget() # re-render widget for the current dataframe if previous rec is not recomputed elif show_prev: - quantitative_columns = [i for i in self.dtypes if i != 'O' and i != 'str'] + quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: self.current_vis = VisList([i for i in self.columns], self) self._widget = rec_df.render_widget() diff --git a/tests/test_action.py b/tests/test_action.py index bcc86cb9..a5f4c139 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -275,13 +275,131 @@ def test_intent_retained(): df._ipython_display_() assert list(df.recommendation.keys()) == ["Enhance", "Filter"] + 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 = 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 - df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}}) - df = df.melt(id_vars=["nPts"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name="type", value_name='t') + df = pd.DataFrame( + { + "nPts": { + 0: 49999, + 1: 71174, + 2: 101317, + 3: 144224, + 4: 205303, + 5: 292249, + 6: 416016, + 7: 592198, + 8: 842993, + 9: 1200000, + }, + "t_heatmap": { + 0: 0.15121674537658691, + 1: 0.1811518669128418, + 2: 0.2179429531097412, + 3: 0.2787730693817139, + 4: 0.3973350524902344, + 5: 0.4233138561248779, + 6: 0.580251932144165, + 7: 0.7928099632263184, + 8: 1.0876789093017578, + 9: 1.6242818832397459, + }, + "t_color_heatmap": { + 0: 0.14242982864379886, + 1: 0.18866705894470212, + 2: 0.1566781997680664, + 3: 0.16737699508666992, + 4: 0.19900894165039065, + 5: 0.2701129913330078, + 6: 0.2533812522888184, + 7: 0.37183785438537603, + 8: 0.3830866813659668, + 9: 0.39321017265319824, + }, + "t_bar": { + 0: 0.01940608024597168, + 1: 0.02618718147277832, + 2: 0.024693727493286133, + 3: 0.029685020446777344, + 4: 0.03471803665161133, + 5: 0.04173588752746582, + 6: 0.04706382751464844, + 7: 0.0667569637298584, + 8: 0.08260798454284668, + 9: 0.1006929874420166, + }, + "t_cbar": { + 0: 0.04185795783996582, + 1: 0.050965070724487305, + 2: 0.052091121673583984, + 3: 0.0610501766204834, + 4: 0.07504606246948242, + 5: 0.09924101829528807, + 6: 0.10392117500305176, + 7: 0.13044309616088867, + 8: 0.18137121200561526, + 9: 0.2069528102874756, + }, + "t_hist": { + 0: 0.01846003532409668, + 1: 0.018136978149414062, + 2: 0.018748998641967773, + 3: 0.01876473426818848, + 4: 0.02434706687927246, + 5: 0.025368213653564453, + 6: 0.02530217170715332, + 7: 0.02823114395141602, + 8: 0.029034852981567383, + 9: 0.034781217575073235, + }, + "t_scatter": { + 0: 0.8179378509521484, + 1: 1.0982017517089844, + 2: 1.4875690937042236, + 3: 2.146117925643921, + 4: 3.1123709678649902, + 5: 3.92416787147522, + 6: 6.097048044204713, + 7: 8.803220987319945, + 8: 12.054464101791382, + 9: 17.740845680236816, + }, + "t_color_scatter": { + 0: 1.3474130630493164, + 1: 1.7953579425811768, + 2: 2.6268541812896733, + 3: 3.646371126174927, + 4: 4.901940107345581, + 5: 6.974237203598023, + 6: 10.197483777999876, + 7: 14.134275913238525, + 8: 21.13951110839844, + 9: 27.127063989639282, + }, + } + ) + df = df.melt( + id_vars=["nPts"], + value_vars=[ + "t_heatmap", + "t_color_heatmap", + "t_bar", + "t_cbar", + "t_hist", + "t_scatter", + "t_color_scatter", + ], + var_name="type", + value_name="t", + ) df._ipython_display_() assert df.current_vis != None From edaad3fe014c1c08000526e496360c06040a24b6 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 7 Apr 2021 09:09:36 -0700 Subject: [PATCH 25/36] tests --- examples/demo.ipynb | 1009 ++++++++++++++++++++++++++++++++++++++++++ lux/core/frame.py | 17 +- tests/test_action.py | 129 ------ tests/test_vis.py | 129 ++++++ 4 files changed, 1149 insertions(+), 135 deletions(-) create mode 100644 examples/demo.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb new file mode 100644 index 00000000..624369b8 --- /dev/null +++ b/examples/demo.ipynb @@ -0,0 +1,1009 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipython-7.22.0-py3.8.egg/IPython/core/formatters.py:345: UserWarning:\n", + "Unexpected error in rendering Lux widget and recommendations. Falling back to Pandas display.\n", + "Please report the following issue on Github: https://github.com/lux-org/lux/issues \n", + "\n", + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py:700: UserWarning:Traceback (most recent call last):\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 535, in get\n", + " value = obj._trait_values[self.name]\n", + "KeyError: 'layout'\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 230, in extract_header\n", + " h = msg_or_header['header']\n", + "KeyError: 'header'\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py\", line 651, in _repr_html_\n", + " self.maintain_recs()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py\", line 493, in maintain_recs\n", + " self._widget = rec_df.render_widget()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py\", line 750, in render_widget\n", + " return luxwidget.LuxWidget(\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/luxwidget/widget.py\", line 28, in __init__\n", + " super().__init__(**kwargs)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", + " self.open()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 399, in open\n", + " state, buffer_paths, buffers = _remove_buffers(self.get_state())\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 489, in get_state\n", + " value = to_json(getattr(self, k), self)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 575, in __get__\n", + " return self.get(obj, cls)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 538, in get\n", + " default = obj.trait_defaults(self.name)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 1578, in trait_defaults\n", + " return self._get_trait_default_generator(names[0])(self)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 511, in default\n", + " return self.make_dynamic_default()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/trait_types.py\", line 194, in make_dynamic_default\n", + " return self.klass(*(self.default_args or ()),\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", + " self.open()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 409, in open\n", + " self.comm = Comm(**args)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 57, in __init__\n", + " self.open(data=data, metadata=metadata, buffers=buffers)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 91, in open\n", + " self._publish_msg('comm_open',\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 66, in _publish_msg\n", + " self.kernel.session.send(self.kernel.iopub_socket, msg_type,\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 717, in send\n", + " msg = self.msg(msg_or_type, content=content, parent=parent,\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 581, in msg\n", + " msg['parent_header'] = {} if parent is None else extract_header(parent)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 234, in extract_header\n", + " h = msg_or_header['msg_id']\n", + "KeyError: 'msg_id'\n", + "\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
SoldPricePerSqftPctForeclosuredPctIncreasingMetroCountyTurnoverMonthPctDecreasingListingPricePerSqftPctPriceReductionsForeclosuresRatioStatePriceToRentRatioSaleToListRatioListingPriceNumberForRentSoldPriceCityYearQuarter
0185.43211.375599.74RiversideSan Bernardino6.07531900-01-010.170.0000000.00000.84240CA0.000.000000.0317750.0Chino2004-01-011
1197.64870.741099.82RiversideSan Bernardino6.06971900-02-010.100.0000000.00000.66370CA0.000.000000.0331000.0Chino2004-01-011
2197.57350.914099.88RiversideSan Bernardino6.14321900-03-010.060.0000000.00001.10700CA0.000.000000.0345250.0Chino2004-01-011
3203.50911.087099.90RiversideSan Bernardino6.17151900-04-010.080.0000000.00000.71740CA0.000.000000.0361250.0Chino2004-01-012
4210.08944.565299.95RiversideSan Bernardino6.08671900-05-010.050.0000000.00000.50605CA0.000.000000.0365950.0Chino2004-01-012
...............................................................
13795207.09923.509553.86PhiladelphiaMontgomery4.64411900-02-0137.66233.09426212.77782.80300PA15.880.933567500060.0527450.0Lower Merion Township2015-01-011
13796202.78593.944554.56PhiladelphiaMontgomery4.65421900-03-0137.320.0000000.00002.47990PA15.940.0000076.0548250.0Lower Merion Township2015-01-011
13797207.15206.581252.64PhiladelphiaMontgomery4.66431900-04-0137.300.0000000.00002.69020PA15.840.0000083.0634425.0Lower Merion Township2015-01-012
13798204.75345.429250.47PhiladelphiaMontgomery4.52351900-05-0137.670.0000000.00002.67140PA15.640.00000110.0640375.0Lower Merion Township2015-01-012
13799208.22993.943247.76PhiladelphiaMontgomery4.35261900-06-0139.450.0000000.00003.56090PA15.560.00000120.0557225.0Lower Merion Township2015-01-012
\n", + "

13800 rows × 20 columns

\n", + "
" + ], + "text/plain": [ + " SoldPricePerSqft PctForeclosured PctIncreasing Metro \\\n", + "0 185.4321 1.3755 99.74 Riverside \n", + "1 197.6487 0.7410 99.82 Riverside \n", + "2 197.5735 0.9140 99.88 Riverside \n", + "3 203.5091 1.0870 99.90 Riverside \n", + "4 210.0894 4.5652 99.95 Riverside \n", + "... ... ... ... ... \n", + "13795 207.0992 3.5095 53.86 Philadelphia \n", + "13796 202.7859 3.9445 54.56 Philadelphia \n", + "13797 207.1520 6.5812 52.64 Philadelphia \n", + "13798 204.7534 5.4292 50.47 Philadelphia \n", + "13799 208.2299 3.9432 47.76 Philadelphia \n", + "\n", + " County Turnover Month PctDecreasing \\\n", + "0 San Bernardino 6.0753 1900-01-01 0.17 \n", + "1 San Bernardino 6.0697 1900-02-01 0.10 \n", + "2 San Bernardino 6.1432 1900-03-01 0.06 \n", + "3 San Bernardino 6.1715 1900-04-01 0.08 \n", + "4 San Bernardino 6.0867 1900-05-01 0.05 \n", + "... ... ... ... ... \n", + "13795 Montgomery 4.6441 1900-02-01 37.66 \n", + "13796 Montgomery 4.6542 1900-03-01 37.32 \n", + "13797 Montgomery 4.6643 1900-04-01 37.30 \n", + "13798 Montgomery 4.5235 1900-05-01 37.67 \n", + "13799 Montgomery 4.3526 1900-06-01 39.45 \n", + "\n", + " ListingPricePerSqft PctPriceReductions ForeclosuresRatio State \\\n", + "0 0.000000 0.0000 0.84240 CA \n", + "1 0.000000 0.0000 0.66370 CA \n", + "2 0.000000 0.0000 1.10700 CA \n", + "3 0.000000 0.0000 0.71740 CA \n", + "4 0.000000 0.0000 0.50605 CA \n", + "... ... ... ... ... \n", + "13795 233.094262 12.7778 2.80300 PA \n", + "13796 0.000000 0.0000 2.47990 PA \n", + "13797 0.000000 0.0000 2.69020 PA \n", + "13798 0.000000 0.0000 2.67140 PA \n", + "13799 0.000000 0.0000 3.56090 PA \n", + "\n", + " PriceToRentRatio SaleToListRatio ListingPrice NumberForRent \\\n", + "0 0.00 0.0000 0 0.0 \n", + "1 0.00 0.0000 0 0.0 \n", + "2 0.00 0.0000 0 0.0 \n", + "3 0.00 0.0000 0 0.0 \n", + "4 0.00 0.0000 0 0.0 \n", + "... ... ... ... ... \n", + "13795 15.88 0.9335 675000 60.0 \n", + "13796 15.94 0.0000 0 76.0 \n", + "13797 15.84 0.0000 0 83.0 \n", + "13798 15.64 0.0000 0 110.0 \n", + "13799 15.56 0.0000 0 120.0 \n", + "\n", + " SoldPrice City Year Quarter \n", + "0 317750.0 Chino 2004-01-01 1 \n", + "1 331000.0 Chino 2004-01-01 1 \n", + "2 345250.0 Chino 2004-01-01 1 \n", + "3 361250.0 Chino 2004-01-01 2 \n", + "4 365950.0 Chino 2004-01-01 2 \n", + "... ... ... ... ... \n", + "13795 527450.0 Lower Merion Township 2015-01-01 1 \n", + "13796 548250.0 Lower Merion Township 2015-01-01 1 \n", + "13797 634425.0 Lower Merion Township 2015-01-01 2 \n", + "13798 640375.0 Lower Merion Township 2015-01-01 2 \n", + "13799 557225.0 Lower Merion Township 2015-01-01 2 \n", + "\n", + "[13800 rows x 20 columns]" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", + "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", + "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", + "df.intent = [\n", + " lux.Clause(\"Year\"),\n", + " lux.Clause(\"PctForeclosured\"),\n", + " lux.Clause(\"City=Crofton\"),\n", + "]\n", + "df\n", + "# vis = df.recommendation[\"Similarity\"][0]\n", + "# vis\n", + "# vis.data" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipython-7.22.0-py3.8.egg/IPython/core/formatters.py:918: UserWarning:\n", + "Unexpected error in rendering Lux widget and recommendations. Falling back to Pandas display.\n", + "Please report the following issue on Github: https://github.com/lux-org/lux/issues \n", + "\n", + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py:686: UserWarning:Traceback (most recent call last):\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 535, in get\n", + " value = obj._trait_values[self.name]\n", + "KeyError: 'layout'\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 230, in extract_header\n", + " h = msg_or_header['header']\n", + "KeyError: 'header'\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py\", line 648, in _ipython_display_\n", + " self.maintain_recs()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py\", line 504, in maintain_recs\n", + " self._widget = rec_df.render_widget()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py\", line 736, in render_widget\n", + " return luxwidget.LuxWidget(\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_widget-0.1.4-py3.8.egg/luxwidget/widget.py\", line 27, in __init__\n", + " super().__init__(**kwargs)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", + " self.open()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 399, in open\n", + " state, buffer_paths, buffers = _remove_buffers(self.get_state())\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 489, in get_state\n", + " value = to_json(getattr(self, k), self)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 575, in __get__\n", + " return self.get(obj, cls)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 538, in get\n", + " default = obj.trait_defaults(self.name)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 1578, in trait_defaults\n", + " return self._get_trait_default_generator(names[0])(self)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 511, in default\n", + " return self.make_dynamic_default()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/trait_types.py\", line 194, in make_dynamic_default\n", + " return self.klass(*(self.default_args or ()),\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", + " self.open()\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 409, in open\n", + " self.comm = Comm(**args)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 57, in __init__\n", + " self.open(data=data, metadata=metadata, buffers=buffers)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 91, in open\n", + " self._publish_msg('comm_open',\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 66, in _publish_msg\n", + " self.kernel.session.send(self.kernel.iopub_socket, msg_type,\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 717, in send\n", + " msg = self.msg(msg_or_type, content=content, parent=parent,\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 581, in msg\n", + " msg['parent_header'] = {} if parent is None else extract_header(parent)\n", + " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 234, in extract_header\n", + " h = msg_or_header['msg_id']\n", + "KeyError: 'msg_id'\n", + "\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTemp
01944-01-0122.2
11944-01-0323.9
21944-01-0422.2
31944-01-0622.8
41944-01-0722.2
.........
154312015-02-2428.6
154322015-02-2528.6
154332015-02-2627.6
154342015-02-2727.6
154352015-02-2829.2
\n", + "

15436 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " Date Temp\n", + "0 1944-01-01 22.2\n", + "1 1944-01-03 23.9\n", + "2 1944-01-04 22.2\n", + "3 1944-01-06 22.8\n", + "4 1944-01-07 22.2\n", + "... ... ...\n", + "15431 2015-02-24 28.6\n", + "15432 2015-02-25 28.6\n", + "15433 2015-02-26 27.6\n", + "15434 2015-02-27 27.6\n", + "15435 2015-02-28 29.2\n", + "\n", + "[15436 rows x 2 columns]" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax\n", + "# tmax.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in tmax.columns], tmax)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "18dbaa0c77d940548a45653e8b4dac4b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4a05513659e7486a8aa8591de35f789d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "# df['time'] = pd.to_datetime(df['time'], format='')\n", + "# df.set_data_type({'time':'quantitative'})\n", + "\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", + "pdf\n", + "# pdf.dtypes\n", + "pdf.set_data_type({'time':'quantitative'})\n", + "pdf\n", + "# pdf.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in pdf.columns], pdf)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n" + ] + }, + { + "data": { + "text/plain": [ + "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lux/core/frame.py b/lux/core/frame.py index b1f08053..48212564 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -84,6 +84,7 @@ def __init__(self, *args, **kw): self.pre_aggregated = None self._type_override = {} warnings.formatwarning = lux.warning_format + self.all_column = False @property def _constructor(self): @@ -425,6 +426,12 @@ 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): + quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] + if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: + self.current_vis = VisList([i for i in self.columns], self) + self.all_column = True + 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 @@ -498,15 +505,11 @@ def maintain_recs(self, is_series="DataFrame"): if len(vlist) > 0: rec_df._recommendation[action_type] = vlist rec_df._rec_info = rec_infolist - quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] - if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: - self.current_vis = VisList([i for i in self.columns], self) + 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: - quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] - if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: - self.current_vis = VisList([i for i in self.columns], self) + rec_df.show_all_column_vis() self._widget = rec_df.render_widget() self._recs_fresh = True @@ -733,11 +736,13 @@ def render_widget(self, renderer: str = "altair", input_current_vis=""): import luxwidget widgetJSON = self.to_JSON(self._rec_info, input_current_vis=input_current_vis) + return luxwidget.LuxWidget( currentVis=widgetJSON["current_vis"], recommendations=widgetJSON["recommendation"], intent=LuxDataFrame.intent_to_string(self._intent), message=self._message.to_html(), + all_column=self.all_column, ) @staticmethod diff --git a/tests/test_action.py b/tests/test_action.py index a5f4c139..5e22938c 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -274,132 +274,3 @@ def test_intent_retained(): df._ipython_display_() assert list(df.recommendation.keys()) == ["Enhance", "Filter"] - - -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 - - df = pd.DataFrame( - { - "nPts": { - 0: 49999, - 1: 71174, - 2: 101317, - 3: 144224, - 4: 205303, - 5: 292249, - 6: 416016, - 7: 592198, - 8: 842993, - 9: 1200000, - }, - "t_heatmap": { - 0: 0.15121674537658691, - 1: 0.1811518669128418, - 2: 0.2179429531097412, - 3: 0.2787730693817139, - 4: 0.3973350524902344, - 5: 0.4233138561248779, - 6: 0.580251932144165, - 7: 0.7928099632263184, - 8: 1.0876789093017578, - 9: 1.6242818832397459, - }, - "t_color_heatmap": { - 0: 0.14242982864379886, - 1: 0.18866705894470212, - 2: 0.1566781997680664, - 3: 0.16737699508666992, - 4: 0.19900894165039065, - 5: 0.2701129913330078, - 6: 0.2533812522888184, - 7: 0.37183785438537603, - 8: 0.3830866813659668, - 9: 0.39321017265319824, - }, - "t_bar": { - 0: 0.01940608024597168, - 1: 0.02618718147277832, - 2: 0.024693727493286133, - 3: 0.029685020446777344, - 4: 0.03471803665161133, - 5: 0.04173588752746582, - 6: 0.04706382751464844, - 7: 0.0667569637298584, - 8: 0.08260798454284668, - 9: 0.1006929874420166, - }, - "t_cbar": { - 0: 0.04185795783996582, - 1: 0.050965070724487305, - 2: 0.052091121673583984, - 3: 0.0610501766204834, - 4: 0.07504606246948242, - 5: 0.09924101829528807, - 6: 0.10392117500305176, - 7: 0.13044309616088867, - 8: 0.18137121200561526, - 9: 0.2069528102874756, - }, - "t_hist": { - 0: 0.01846003532409668, - 1: 0.018136978149414062, - 2: 0.018748998641967773, - 3: 0.01876473426818848, - 4: 0.02434706687927246, - 5: 0.025368213653564453, - 6: 0.02530217170715332, - 7: 0.02823114395141602, - 8: 0.029034852981567383, - 9: 0.034781217575073235, - }, - "t_scatter": { - 0: 0.8179378509521484, - 1: 1.0982017517089844, - 2: 1.4875690937042236, - 3: 2.146117925643921, - 4: 3.1123709678649902, - 5: 3.92416787147522, - 6: 6.097048044204713, - 7: 8.803220987319945, - 8: 12.054464101791382, - 9: 17.740845680236816, - }, - "t_color_scatter": { - 0: 1.3474130630493164, - 1: 1.7953579425811768, - 2: 2.6268541812896733, - 3: 3.646371126174927, - 4: 4.901940107345581, - 5: 6.974237203598023, - 6: 10.197483777999876, - 7: 14.134275913238525, - 8: 21.13951110839844, - 9: 27.127063989639282, - }, - } - ) - df = df.melt( - id_vars=["nPts"], - value_vars=[ - "t_heatmap", - "t_color_heatmap", - "t_bar", - "t_cbar", - "t_hist", - "t_scatter", - "t_color_scatter", - ], - var_name="type", - value_name="t", - ) - df._ipython_display_() - assert df.current_vis != None diff --git a/tests/test_vis.py b/tests/test_vis.py index 4caf74ea..0832dc53 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -525,3 +525,132 @@ 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 + + df = pd.DataFrame( + { + "nPts": { + 0: 49999, + 1: 71174, + 2: 101317, + 3: 144224, + 4: 205303, + 5: 292249, + 6: 416016, + 7: 592198, + 8: 842993, + 9: 1200000, + }, + "t_heatmap": { + 0: 0.15121674537658691, + 1: 0.1811518669128418, + 2: 0.2179429531097412, + 3: 0.2787730693817139, + 4: 0.3973350524902344, + 5: 0.4233138561248779, + 6: 0.580251932144165, + 7: 0.7928099632263184, + 8: 1.0876789093017578, + 9: 1.6242818832397459, + }, + "t_color_heatmap": { + 0: 0.14242982864379886, + 1: 0.18866705894470212, + 2: 0.1566781997680664, + 3: 0.16737699508666992, + 4: 0.19900894165039065, + 5: 0.2701129913330078, + 6: 0.2533812522888184, + 7: 0.37183785438537603, + 8: 0.3830866813659668, + 9: 0.39321017265319824, + }, + "t_bar": { + 0: 0.01940608024597168, + 1: 0.02618718147277832, + 2: 0.024693727493286133, + 3: 0.029685020446777344, + 4: 0.03471803665161133, + 5: 0.04173588752746582, + 6: 0.04706382751464844, + 7: 0.0667569637298584, + 8: 0.08260798454284668, + 9: 0.1006929874420166, + }, + "t_cbar": { + 0: 0.04185795783996582, + 1: 0.050965070724487305, + 2: 0.052091121673583984, + 3: 0.0610501766204834, + 4: 0.07504606246948242, + 5: 0.09924101829528807, + 6: 0.10392117500305176, + 7: 0.13044309616088867, + 8: 0.18137121200561526, + 9: 0.2069528102874756, + }, + "t_hist": { + 0: 0.01846003532409668, + 1: 0.018136978149414062, + 2: 0.018748998641967773, + 3: 0.01876473426818848, + 4: 0.02434706687927246, + 5: 0.025368213653564453, + 6: 0.02530217170715332, + 7: 0.02823114395141602, + 8: 0.029034852981567383, + 9: 0.034781217575073235, + }, + "t_scatter": { + 0: 0.8179378509521484, + 1: 1.0982017517089844, + 2: 1.4875690937042236, + 3: 2.146117925643921, + 4: 3.1123709678649902, + 5: 3.92416787147522, + 6: 6.097048044204713, + 7: 8.803220987319945, + 8: 12.054464101791382, + 9: 17.740845680236816, + }, + "t_color_scatter": { + 0: 1.3474130630493164, + 1: 1.7953579425811768, + 2: 2.6268541812896733, + 3: 3.646371126174927, + 4: 4.901940107345581, + 5: 6.974237203598023, + 6: 10.197483777999876, + 7: 14.134275913238525, + 8: 21.13951110839844, + 9: 27.127063989639282, + }, + } + ) + df = df.melt( + id_vars=["nPts"], + value_vars=[ + "t_heatmap", + "t_color_heatmap", + "t_bar", + "t_cbar", + "t_hist", + "t_scatter", + "t_color_scatter", + ], + var_name="type", + value_name="t", + ) + df._ipython_display_() + assert df.current_vis != None From bfba8b7afd1717d453e7204bb1854f795428ab1f Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Wed, 7 Apr 2021 09:10:34 -0700 Subject: [PATCH 26/36] rm --- examples/demo.ipynb | 1009 ------------------------------------------- 1 file changed, 1009 deletions(-) delete mode 100644 examples/demo.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb deleted file mode 100644 index 624369b8..00000000 --- a/examples/demo.ipynb +++ /dev/null @@ -1,1009 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipython-7.22.0-py3.8.egg/IPython/core/formatters.py:345: UserWarning:\n", - "Unexpected error in rendering Lux widget and recommendations. Falling back to Pandas display.\n", - "Please report the following issue on Github: https://github.com/lux-org/lux/issues \n", - "\n", - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py:700: UserWarning:Traceback (most recent call last):\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 535, in get\n", - " value = obj._trait_values[self.name]\n", - "KeyError: 'layout'\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 230, in extract_header\n", - " h = msg_or_header['header']\n", - "KeyError: 'header'\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py\", line 651, in _repr_html_\n", - " self.maintain_recs()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py\", line 493, in maintain_recs\n", - " self._widget = rec_df.render_widget()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux/core/frame.py\", line 750, in render_widget\n", - " return luxwidget.LuxWidget(\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/luxwidget/widget.py\", line 28, in __init__\n", - " super().__init__(**kwargs)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", - " self.open()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 399, in open\n", - " state, buffer_paths, buffers = _remove_buffers(self.get_state())\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 489, in get_state\n", - " value = to_json(getattr(self, k), self)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 575, in __get__\n", - " return self.get(obj, cls)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 538, in get\n", - " default = obj.trait_defaults(self.name)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 1578, in trait_defaults\n", - " return self._get_trait_default_generator(names[0])(self)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 511, in default\n", - " return self.make_dynamic_default()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/trait_types.py\", line 194, in make_dynamic_default\n", - " return self.klass(*(self.default_args or ()),\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", - " self.open()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 409, in open\n", - " self.comm = Comm(**args)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 57, in __init__\n", - " self.open(data=data, metadata=metadata, buffers=buffers)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 91, in open\n", - " self._publish_msg('comm_open',\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 66, in _publish_msg\n", - " self.kernel.session.send(self.kernel.iopub_socket, msg_type,\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 717, in send\n", - " msg = self.msg(msg_or_type, content=content, parent=parent,\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 581, in msg\n", - " msg['parent_header'] = {} if parent is None else extract_header(parent)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 234, in extract_header\n", - " h = msg_or_header['msg_id']\n", - "KeyError: 'msg_id'\n", - "\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
SoldPricePerSqftPctForeclosuredPctIncreasingMetroCountyTurnoverMonthPctDecreasingListingPricePerSqftPctPriceReductionsForeclosuresRatioStatePriceToRentRatioSaleToListRatioListingPriceNumberForRentSoldPriceCityYearQuarter
0185.43211.375599.74RiversideSan Bernardino6.07531900-01-010.170.0000000.00000.84240CA0.000.000000.0317750.0Chino2004-01-011
1197.64870.741099.82RiversideSan Bernardino6.06971900-02-010.100.0000000.00000.66370CA0.000.000000.0331000.0Chino2004-01-011
2197.57350.914099.88RiversideSan Bernardino6.14321900-03-010.060.0000000.00001.10700CA0.000.000000.0345250.0Chino2004-01-011
3203.50911.087099.90RiversideSan Bernardino6.17151900-04-010.080.0000000.00000.71740CA0.000.000000.0361250.0Chino2004-01-012
4210.08944.565299.95RiversideSan Bernardino6.08671900-05-010.050.0000000.00000.50605CA0.000.000000.0365950.0Chino2004-01-012
...............................................................
13795207.09923.509553.86PhiladelphiaMontgomery4.64411900-02-0137.66233.09426212.77782.80300PA15.880.933567500060.0527450.0Lower Merion Township2015-01-011
13796202.78593.944554.56PhiladelphiaMontgomery4.65421900-03-0137.320.0000000.00002.47990PA15.940.0000076.0548250.0Lower Merion Township2015-01-011
13797207.15206.581252.64PhiladelphiaMontgomery4.66431900-04-0137.300.0000000.00002.69020PA15.840.0000083.0634425.0Lower Merion Township2015-01-012
13798204.75345.429250.47PhiladelphiaMontgomery4.52351900-05-0137.670.0000000.00002.67140PA15.640.00000110.0640375.0Lower Merion Township2015-01-012
13799208.22993.943247.76PhiladelphiaMontgomery4.35261900-06-0139.450.0000000.00003.56090PA15.560.00000120.0557225.0Lower Merion Township2015-01-012
\n", - "

13800 rows × 20 columns

\n", - "
" - ], - "text/plain": [ - " SoldPricePerSqft PctForeclosured PctIncreasing Metro \\\n", - "0 185.4321 1.3755 99.74 Riverside \n", - "1 197.6487 0.7410 99.82 Riverside \n", - "2 197.5735 0.9140 99.88 Riverside \n", - "3 203.5091 1.0870 99.90 Riverside \n", - "4 210.0894 4.5652 99.95 Riverside \n", - "... ... ... ... ... \n", - "13795 207.0992 3.5095 53.86 Philadelphia \n", - "13796 202.7859 3.9445 54.56 Philadelphia \n", - "13797 207.1520 6.5812 52.64 Philadelphia \n", - "13798 204.7534 5.4292 50.47 Philadelphia \n", - "13799 208.2299 3.9432 47.76 Philadelphia \n", - "\n", - " County Turnover Month PctDecreasing \\\n", - "0 San Bernardino 6.0753 1900-01-01 0.17 \n", - "1 San Bernardino 6.0697 1900-02-01 0.10 \n", - "2 San Bernardino 6.1432 1900-03-01 0.06 \n", - "3 San Bernardino 6.1715 1900-04-01 0.08 \n", - "4 San Bernardino 6.0867 1900-05-01 0.05 \n", - "... ... ... ... ... \n", - "13795 Montgomery 4.6441 1900-02-01 37.66 \n", - "13796 Montgomery 4.6542 1900-03-01 37.32 \n", - "13797 Montgomery 4.6643 1900-04-01 37.30 \n", - "13798 Montgomery 4.5235 1900-05-01 37.67 \n", - "13799 Montgomery 4.3526 1900-06-01 39.45 \n", - "\n", - " ListingPricePerSqft PctPriceReductions ForeclosuresRatio State \\\n", - "0 0.000000 0.0000 0.84240 CA \n", - "1 0.000000 0.0000 0.66370 CA \n", - "2 0.000000 0.0000 1.10700 CA \n", - "3 0.000000 0.0000 0.71740 CA \n", - "4 0.000000 0.0000 0.50605 CA \n", - "... ... ... ... ... \n", - "13795 233.094262 12.7778 2.80300 PA \n", - "13796 0.000000 0.0000 2.47990 PA \n", - "13797 0.000000 0.0000 2.69020 PA \n", - "13798 0.000000 0.0000 2.67140 PA \n", - "13799 0.000000 0.0000 3.56090 PA \n", - "\n", - " PriceToRentRatio SaleToListRatio ListingPrice NumberForRent \\\n", - "0 0.00 0.0000 0 0.0 \n", - "1 0.00 0.0000 0 0.0 \n", - "2 0.00 0.0000 0 0.0 \n", - "3 0.00 0.0000 0 0.0 \n", - "4 0.00 0.0000 0 0.0 \n", - "... ... ... ... ... \n", - "13795 15.88 0.9335 675000 60.0 \n", - "13796 15.94 0.0000 0 76.0 \n", - "13797 15.84 0.0000 0 83.0 \n", - "13798 15.64 0.0000 0 110.0 \n", - "13799 15.56 0.0000 0 120.0 \n", - "\n", - " SoldPrice City Year Quarter \n", - "0 317750.0 Chino 2004-01-01 1 \n", - "1 331000.0 Chino 2004-01-01 1 \n", - "2 345250.0 Chino 2004-01-01 1 \n", - "3 361250.0 Chino 2004-01-01 2 \n", - "4 365950.0 Chino 2004-01-01 2 \n", - "... ... ... ... ... \n", - "13795 527450.0 Lower Merion Township 2015-01-01 1 \n", - "13796 548250.0 Lower Merion Township 2015-01-01 1 \n", - "13797 634425.0 Lower Merion Township 2015-01-01 2 \n", - "13798 640375.0 Lower Merion Township 2015-01-01 2 \n", - "13799 557225.0 Lower Merion Township 2015-01-01 2 \n", - "\n", - "[13800 rows x 20 columns]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", - "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", - "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", - "df.intent = [\n", - " lux.Clause(\"Year\"),\n", - " lux.Clause(\"PctForeclosured\"),\n", - " lux.Clause(\"City=Crofton\"),\n", - "]\n", - "df\n", - "# vis = df.recommendation[\"Similarity\"][0]\n", - "# vis\n", - "# vis.data" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipython-7.22.0-py3.8.egg/IPython/core/formatters.py:918: UserWarning:\n", - "Unexpected error in rendering Lux widget and recommendations. Falling back to Pandas display.\n", - "Please report the following issue on Github: https://github.com/lux-org/lux/issues \n", - "\n", - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py:686: UserWarning:Traceback (most recent call last):\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 535, in get\n", - " value = obj._trait_values[self.name]\n", - "KeyError: 'layout'\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 230, in extract_header\n", - " h = msg_or_header['header']\n", - "KeyError: 'header'\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py\", line 648, in _ipython_display_\n", - " self.maintain_recs()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py\", line 504, in maintain_recs\n", - " self._widget = rec_df.render_widget()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/core/frame.py\", line 736, in render_widget\n", - " return luxwidget.LuxWidget(\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_widget-0.1.4-py3.8.egg/luxwidget/widget.py\", line 27, in __init__\n", - " super().__init__(**kwargs)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", - " self.open()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 399, in open\n", - " state, buffer_paths, buffers = _remove_buffers(self.get_state())\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 489, in get_state\n", - " value = to_json(getattr(self, k), self)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 575, in __get__\n", - " return self.get(obj, cls)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 538, in get\n", - " default = obj.trait_defaults(self.name)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 1578, in trait_defaults\n", - " return self._get_trait_default_generator(names[0])(self)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/traitlets-5.0.5-py3.8.egg/traitlets/traitlets.py\", line 511, in default\n", - " return self.make_dynamic_default()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/trait_types.py\", line 194, in make_dynamic_default\n", - " return self.klass(*(self.default_args or ()),\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 386, in __init__\n", - " self.open()\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg/ipywidgets/widgets/widget.py\", line 409, in open\n", - " self.comm = Comm(**args)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 57, in __init__\n", - " self.open(data=data, metadata=metadata, buffers=buffers)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 91, in open\n", - " self._publish_msg('comm_open',\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/ipykernel-6.0.0a1-py3.8.egg/ipykernel/comm/comm.py\", line 66, in _publish_msg\n", - " self.kernel.session.send(self.kernel.iopub_socket, msg_type,\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 717, in send\n", - " msg = self.msg(msg_or_type, content=content, parent=parent,\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 581, in msg\n", - " msg['parent_header'] = {} if parent is None else extract_header(parent)\n", - " File \"/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/jupyter_client-6.1.12-py3.8.egg/jupyter_client/session.py\", line 234, in extract_header\n", - " h = msg_or_header['msg_id']\n", - "KeyError: 'msg_id'\n", - "\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
DateTemp
01944-01-0122.2
11944-01-0323.9
21944-01-0422.2
31944-01-0622.8
41944-01-0722.2
.........
154312015-02-2428.6
154322015-02-2528.6
154332015-02-2627.6
154342015-02-2727.6
154352015-02-2829.2
\n", - "

15436 rows × 2 columns

\n", - "
" - ], - "text/plain": [ - " Date Temp\n", - "0 1944-01-01 22.2\n", - "1 1944-01-03 23.9\n", - "2 1944-01-04 22.2\n", - "3 1944-01-06 22.8\n", - "4 1944-01-07 22.2\n", - "... ... ...\n", - "15431 2015-02-24 28.6\n", - "15432 2015-02-25 28.6\n", - "15433 2015-02-26 27.6\n", - "15434 2015-02-27 27.6\n", - "15435 2015-02-28 29.2\n", - "\n", - "[15436 rows x 2 columns]" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax\n", - "# tmax.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in tmax.columns], tmax)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "18dbaa0c77d940548a45653e8b4dac4b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4a05513659e7486a8aa8591de35f789d", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "# df['time'] = pd.to_datetime(df['time'], format='')\n", - "# df.set_data_type({'time':'quantitative'})\n", - "\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", - "pdf\n", - "# pdf.dtypes\n", - "pdf.set_data_type({'time':'quantitative'})\n", - "pdf\n", - "# pdf.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in pdf.columns], pdf)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n" - ] - }, - { - "data": { - "text/plain": [ - "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.2" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From 40b1681d5399bf503b42fca3805624ea9831d9a1 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 15:02:20 -0700 Subject: [PATCH 27/36] fix --- examples/demo.ipynb | 443 +++++++++++++++++++++++++++++++++++++++++++ examples/demo2.ipynb | 443 +++++++++++++++++++++++++++++++++++++++++++ lux/core/frame.py | 2 - 3 files changed, 886 insertions(+), 2 deletions(-) create mode 100644 examples/demo.ipynb create mode 100644 examples/demo2.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb new file mode 100644 index 00000000..2fca3c52 --- /dev/null +++ b/examples/demo.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4c4695f2d8714780a23a248a66629d38", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "31eae106b6de4ac88e9fb49488ea6516", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax\n", + "# tmax.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in tmax.columns], tmax)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c9cda696154d478b8641805507b78f7b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", + "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", + "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", + "df.intent = [\n", + " lux.Clause(\"Year\"),\n", + " lux.Clause(\"PctForeclosured\"),\n", + " lux.Clause(\"City=Crofton\"),\n", + "]\n", + "df\n", + "# vis = df.recommendation[\"Similarity\"][0]\n", + "# vis\n", + "# vis.data" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "18dbaa0c77d940548a45653e8b4dac4b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4a05513659e7486a8aa8591de35f789d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "# df['time'] = pd.to_datetime(df['time'], format='')\n", + "# df.set_data_type({'time':'quantitative'})\n", + "\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", + "pdf\n", + "# pdf.dtypes\n", + "pdf.set_data_type({'time':'quantitative'})\n", + "pdf\n", + "# pdf.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in pdf.columns], pdf)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n" + ] + }, + { + "data": { + "text/plain": [ + "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/demo2.ipynb b/examples/demo2.ipynb new file mode 100644 index 00000000..1e7568fc --- /dev/null +++ b/examples/demo2.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1d61a15b370449e1b6f2f1f7535dc44b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b891fd1e68e14c348be00d152ef0b464", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax\n", + "# tmax.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in tmax.columns], tmax)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c9cda696154d478b8641805507b78f7b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", + "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", + "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", + "df.intent = [\n", + " lux.Clause(\"Year\"),\n", + " lux.Clause(\"PctForeclosured\"),\n", + " lux.Clause(\"City=Crofton\"),\n", + "]\n", + "df\n", + "# vis = df.recommendation[\"Similarity\"][0]\n", + "# vis\n", + "# vis.data" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "18dbaa0c77d940548a45653e8b4dac4b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4a05513659e7486a8aa8591de35f789d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "# df['time'] = pd.to_datetime(df['time'], format='')\n", + "# df.set_data_type({'time':'quantitative'})\n", + "\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", + "pdf\n", + "# pdf.dtypes\n", + "pdf.set_data_type({'time':'quantitative'})\n", + "pdf\n", + "# pdf.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in pdf.columns], pdf)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n" + ] + }, + { + "data": { + "text/plain": [ + "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lux/core/frame.py b/lux/core/frame.py index 01b9ab95..44d6b033 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -734,7 +734,6 @@ def render_widget(self, renderer: str = "altair", input_current_vis=""): """ check_import_lux_widget() import luxwidget - widgetJSON = self.to_JSON(self._rec_info, input_current_vis=input_current_vis) return luxwidget.LuxWidget( @@ -742,7 +741,6 @@ def render_widget(self, renderer: str = "altair", input_current_vis=""): recommendations=widgetJSON["recommendation"], intent=LuxDataFrame.intent_to_string(self._intent), message=self._message.to_html(), - all_column=self.all_column, ) @staticmethod From d15cef26590453be3318d35501debae63ab4d446 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 15:02:33 -0700 Subject: [PATCH 28/36] fix --- examples/demo.ipynb | 443 ------------------------------------------- examples/demo2.ipynb | 443 ------------------------------------------- 2 files changed, 886 deletions(-) delete mode 100644 examples/demo.ipynb delete mode 100644 examples/demo2.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb deleted file mode 100644 index 2fca3c52..00000000 --- a/examples/demo.ipynb +++ /dev/null @@ -1,443 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4c4695f2d8714780a23a248a66629d38", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "31eae106b6de4ac88e9fb49488ea6516", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax\n", - "# tmax.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in tmax.columns], tmax)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c9cda696154d478b8641805507b78f7b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", - "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", - "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", - "df.intent = [\n", - " lux.Clause(\"Year\"),\n", - " lux.Clause(\"PctForeclosured\"),\n", - " lux.Clause(\"City=Crofton\"),\n", - "]\n", - "df\n", - "# vis = df.recommendation[\"Similarity\"][0]\n", - "# vis\n", - "# vis.data" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "18dbaa0c77d940548a45653e8b4dac4b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4a05513659e7486a8aa8591de35f789d", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "# df['time'] = pd.to_datetime(df['time'], format='')\n", - "# df.set_data_type({'time':'quantitative'})\n", - "\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", - "pdf\n", - "# pdf.dtypes\n", - "pdf.set_data_type({'time':'quantitative'})\n", - "pdf\n", - "# pdf.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in pdf.columns], pdf)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n" - ] - }, - { - "data": { - "text/plain": [ - "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/examples/demo2.ipynb b/examples/demo2.ipynb deleted file mode 100644 index 1e7568fc..00000000 --- a/examples/demo2.ipynb +++ /dev/null @@ -1,443 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "1d61a15b370449e1b6f2f1f7535dc44b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "b891fd1e68e14c348be00d152ef0b464", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax\n", - "# tmax.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in tmax.columns], tmax)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c9cda696154d478b8641805507b78f7b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", - "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", - "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", - "df.intent = [\n", - " lux.Clause(\"Year\"),\n", - " lux.Clause(\"PctForeclosured\"),\n", - " lux.Clause(\"City=Crofton\"),\n", - "]\n", - "df\n", - "# vis = df.recommendation[\"Similarity\"][0]\n", - "# vis\n", - "# vis.data" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "18dbaa0c77d940548a45653e8b4dac4b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4a05513659e7486a8aa8591de35f789d", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "# df['time'] = pd.to_datetime(df['time'], format='')\n", - "# df.set_data_type({'time':'quantitative'})\n", - "\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", - "pdf\n", - "# pdf.dtypes\n", - "pdf.set_data_type({'time':'quantitative'})\n", - "pdf\n", - "# pdf.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in pdf.columns], pdf)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n" - ] - }, - { - "data": { - "text/plain": [ - "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From 16a323ba309856e6f58792362941b9bfa750d37e Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 15:08:22 -0700 Subject: [PATCH 29/36] del --- lux/core/frame.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lux/core/frame.py b/lux/core/frame.py index 44d6b033..7a8d2163 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -430,7 +430,6 @@ def show_all_column_vis(self): quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: self.current_vis = VisList([i for i in self.columns], self) - self.all_column = True def maintain_recs(self, is_series="DataFrame"): # `rec_df` is the dataframe to generate the recommendations on From 3920ba57acaf8aeddbc2db6f1507c82ac033a9cc Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 17:24:14 -0700 Subject: [PATCH 30/36] black --- lux/core/frame.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lux/core/frame.py b/lux/core/frame.py index 7a8d2163..215cf529 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -733,8 +733,9 @@ def render_widget(self, renderer: str = "altair", input_current_vis=""): """ check_import_lux_widget() import luxwidget + widgetJSON = self.to_JSON(self._rec_info, input_current_vis=input_current_vis) - + return luxwidget.LuxWidget( currentVis=widgetJSON["current_vis"], recommendations=widgetJSON["recommendation"], From 524a25223790e9decde81cd46f3d0593ad2d6d26 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 21:11:25 -0700 Subject: [PATCH 31/36] add tests --- examples/demo.ipynb | 443 +++++++++++++++++++++++++++++++++++++++++++ examples/demo2.ipynb | 429 +++++++++++++++++++++++++++++++++++++++++ tests/test_vis.py | 131 ++----------- 3 files changed, 889 insertions(+), 114 deletions(-) create mode 100644 examples/demo.ipynb create mode 100644 examples/demo2.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb new file mode 100644 index 00000000..2fca3c52 --- /dev/null +++ b/examples/demo.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4c4695f2d8714780a23a248a66629d38", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "31eae106b6de4ac88e9fb49488ea6516", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax\n", + "# tmax.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in tmax.columns], tmax)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c9cda696154d478b8641805507b78f7b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", + "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", + "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", + "df.intent = [\n", + " lux.Clause(\"Year\"),\n", + " lux.Clause(\"PctForeclosured\"),\n", + " lux.Clause(\"City=Crofton\"),\n", + "]\n", + "df\n", + "# vis = df.recommendation[\"Similarity\"][0]\n", + "# vis\n", + "# vis.data" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "18dbaa0c77d940548a45653e8b4dac4b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4a05513659e7486a8aa8591de35f789d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "# df['time'] = pd.to_datetime(df['time'], format='')\n", + "# df.set_data_type({'time':'quantitative'})\n", + "\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", + "pdf\n", + "# pdf.dtypes\n", + "pdf.set_data_type({'time':'quantitative'})\n", + "pdf\n", + "# pdf.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in pdf.columns], pdf)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n" + ] + }, + { + "data": { + "text/plain": [ + "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/demo2.ipynb b/examples/demo2.ipynb new file mode 100644 index 00000000..17cc0a16 --- /dev/null +++ b/examples/demo2.ipynb @@ -0,0 +1,429 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import lux" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "lux.config.default_display=\"lux\"\n", + "lux.config.plotting_backend=\"matplotlib\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- tested short column header \"A\", \"B\", working as expected" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5040ae8c46b845fea62cf21c33277c92", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", + "tmax.columns = ['Date', 'Temp']\n", + "tmax\n", + "# tmax.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in tmax.columns], tmax)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c9cda696154d478b8641805507b78f7b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", + "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", + "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", + "df.intent = [\n", + " lux.Clause(\"Year\"),\n", + " lux.Clause(\"PctForeclosured\"),\n", + " lux.Clause(\"City=Crofton\"),\n", + "]\n", + "df\n", + "# vis = df.recommendation[\"Similarity\"][0]\n", + "# vis\n", + "# vis.data" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "18dbaa0c77d940548a45653e8b4dac4b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4a05513659e7486a8aa8591de35f789d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", + "# df['time'] = pd.to_datetime(df['time'], format='')\n", + "# df.set_data_type({'time':'quantitative'})\n", + "\n", + "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", + "pdf\n", + "# pdf.dtypes\n", + "pdf.set_data_type({'time':'quantitative'})\n", + "pdf\n", + "# pdf.columns\n", + "# from lux.vis.VisList import VisList\n", + "# vis = VisList([i for i in pdf.columns], pdf)\n", + "# vis" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", + "Lux detects that the attribute 'Year' may be temporal.\n", + "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", + "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", + "\n", + "Here is a starter template that you can use for converting the temporal fields:\n", + "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", + "\n", + "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", + "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", + "\tdf.set_data_type({'Year':'quantitative'})\n" + ] + }, + { + "data": { + "text/plain": [ + "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.recommendation" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9a8055bad9484cbbab861000b3af8f28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f69914ca65fd48538340836781da8d79", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.exported[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# import altair as alt\n", + "# alt.Chart(df).mark_bar().encode(\n", + "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", + "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", + "# )\n", + "import altair as alt\n", + "import pandas as pd\n", + "source = pd.DataFrame({\n", + " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", + " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", + "})\n", + "chart = alt.Chart(source).mark_bar().encode(\n", + " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", + " y=alt.Y('b')\n", + ")\n", + "chart.encoding.x.axis.title = 'a...'\n", + "chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", + "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.columns = df.columns.str.replace(\".\",\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.data_model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/tests/test_vis.py b/tests/test_vis.py index 0832dc53..2f7b004a 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -538,119 +538,22 @@ def test_all_column_current_vis(): df._ipython_display_() assert df.current_vis != None - df = pd.DataFrame( - { - "nPts": { - 0: 49999, - 1: 71174, - 2: 101317, - 3: 144224, - 4: 205303, - 5: 292249, - 6: 416016, - 7: 592198, - 8: 842993, - 9: 1200000, - }, - "t_heatmap": { - 0: 0.15121674537658691, - 1: 0.1811518669128418, - 2: 0.2179429531097412, - 3: 0.2787730693817139, - 4: 0.3973350524902344, - 5: 0.4233138561248779, - 6: 0.580251932144165, - 7: 0.7928099632263184, - 8: 1.0876789093017578, - 9: 1.6242818832397459, - }, - "t_color_heatmap": { - 0: 0.14242982864379886, - 1: 0.18866705894470212, - 2: 0.1566781997680664, - 3: 0.16737699508666992, - 4: 0.19900894165039065, - 5: 0.2701129913330078, - 6: 0.2533812522888184, - 7: 0.37183785438537603, - 8: 0.3830866813659668, - 9: 0.39321017265319824, - }, - "t_bar": { - 0: 0.01940608024597168, - 1: 0.02618718147277832, - 2: 0.024693727493286133, - 3: 0.029685020446777344, - 4: 0.03471803665161133, - 5: 0.04173588752746582, - 6: 0.04706382751464844, - 7: 0.0667569637298584, - 8: 0.08260798454284668, - 9: 0.1006929874420166, - }, - "t_cbar": { - 0: 0.04185795783996582, - 1: 0.050965070724487305, - 2: 0.052091121673583984, - 3: 0.0610501766204834, - 4: 0.07504606246948242, - 5: 0.09924101829528807, - 6: 0.10392117500305176, - 7: 0.13044309616088867, - 8: 0.18137121200561526, - 9: 0.2069528102874756, - }, - "t_hist": { - 0: 0.01846003532409668, - 1: 0.018136978149414062, - 2: 0.018748998641967773, - 3: 0.01876473426818848, - 4: 0.02434706687927246, - 5: 0.025368213653564453, - 6: 0.02530217170715332, - 7: 0.02823114395141602, - 8: 0.029034852981567383, - 9: 0.034781217575073235, - }, - "t_scatter": { - 0: 0.8179378509521484, - 1: 1.0982017517089844, - 2: 1.4875690937042236, - 3: 2.146117925643921, - 4: 3.1123709678649902, - 5: 3.92416787147522, - 6: 6.097048044204713, - 7: 8.803220987319945, - 8: 12.054464101791382, - 9: 17.740845680236816, - }, - "t_color_scatter": { - 0: 1.3474130630493164, - 1: 1.7953579425811768, - 2: 2.6268541812896733, - 3: 3.646371126174927, - 4: 4.901940107345581, - 5: 6.974237203598023, - 6: 10.197483777999876, - 7: 14.134275913238525, - 8: 21.13951110839844, - 9: 27.127063989639282, - }, - } - ) - df = df.melt( - id_vars=["nPts"], - value_vars=[ - "t_heatmap", - "t_color_heatmap", - "t_bar", - "t_cbar", - "t_hist", - "t_scatter", - "t_color_scatter", - ], - var_name="type", - value_name="t", - ) +def test_all_column_current_vis_filter(): + lux.config.plotting_backend = "matplotlib" + df = pytest.car_df + df = df[["Year", "Displacement"]] + df._ipython_display_() + assert df.current_vis != None + + df = df[["Year", "Displacement", "Origin"]] + df._ipython_display_() + +def test_intent_override_all_column(): + lux.config.plotting_backend = "matplotlib" + df = pytest.car_df + df = df[["Year", "Displacement"]] + df.intent = ["Year"] df._ipython_display_() assert df.current_vis != None + lux.config.plotting_backend = "altair" + From d9253a339fb24f2845256345616c12bb6715a597 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 22:14:12 -0700 Subject: [PATCH 32/36] tests updated --- examples/demo.ipynb | 443 ------------------------- examples/demo2.ipynb | 429 ------------------------ lux/_config/config.py | 21 +- lux/action/generalize.py | 7 +- lux/action/row_group.py | 8 +- lux/core/frame.py | 14 +- lux/core/series.py | 3 +- lux/executor/PandasExecutor.py | 10 +- lux/executor/SQLExecutor.py | 6 +- lux/interestingness/interestingness.py | 6 +- lux/interestingness/similarity.py | 3 +- lux/processor/Compiler.py | 9 +- lux/vislib/altair/AltairRenderer.py | 3 +- lux/vislib/altair/Choropleth.py | 4 +- lux/vislib/altair/Heatmap.py | 5 +- tests/test_action.py | 23 +- tests/test_compiler.py | 49 +-- tests/test_dates.py | 5 +- tests/test_interestingness.py | 10 +- tests/test_pandas_coverage.py | 8 +- tests/test_parser.py | 3 +- tests/test_vis.py | 11 +- 22 files changed, 51 insertions(+), 1029 deletions(-) delete mode 100644 examples/demo.ipynb delete mode 100644 examples/demo2.ipynb diff --git a/examples/demo.ipynb b/examples/demo.ipynb deleted file mode 100644 index 2fca3c52..00000000 --- a/examples/demo.ipynb +++ /dev/null @@ -1,443 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4c4695f2d8714780a23a248a66629d38", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "31eae106b6de4ac88e9fb49488ea6516", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax\n", - "# tmax.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in tmax.columns], tmax)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c9cda696154d478b8641805507b78f7b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", - "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", - "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", - "df.intent = [\n", - " lux.Clause(\"Year\"),\n", - " lux.Clause(\"PctForeclosured\"),\n", - " lux.Clause(\"City=Crofton\"),\n", - "]\n", - "df\n", - "# vis = df.recommendation[\"Similarity\"][0]\n", - "# vis\n", - "# vis.data" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "18dbaa0c77d940548a45653e8b4dac4b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4a05513659e7486a8aa8591de35f789d", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "# df['time'] = pd.to_datetime(df['time'], format='')\n", - "# df.set_data_type({'time':'quantitative'})\n", - "\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", - "pdf\n", - "# pdf.dtypes\n", - "pdf.set_data_type({'time':'quantitative'})\n", - "pdf\n", - "# pdf.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in pdf.columns], pdf)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n" - ] - }, - { - "data": { - "text/plain": [ - "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/examples/demo2.ipynb b/examples/demo2.ipynb deleted file mode 100644 index 17cc0a16..00000000 --- a/examples/demo2.ipynb +++ /dev/null @@ -1,429 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ls" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import lux" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "lux.config.default_display=\"lux\"\n", - "lux.config.plotting_backend=\"matplotlib\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- tested short column header \"A\", \"B\", working as expected" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5040ae8c46b845fea62cf21c33277c92", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "tmax = pd.read_csv('https://raw.githubusercontent.com/koldunovn/python_for_geosciences/master/DelhiTmax.txt', delimiter=r\"\\s+\", parse_dates=[[0,1,2]], header=None)\n", - "tmax.columns = ['Date', 'Temp']\n", - "tmax\n", - "# tmax.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in tmax.columns], tmax)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5bac9a68d1f94f79b3a5e33d5820dc54", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c9cda696154d478b8641805507b78f7b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.read_csv(\"https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/real_estate_tutorial.csv\")\n", - "df[\"Month\"] = pd.to_datetime(df[\"Month\"], format=\"%m\")\n", - "df[\"Year\"] = pd.to_datetime(df[\"Year\"], format=\"%Y\")\n", - "df.intent = [\n", - " lux.Clause(\"Year\"),\n", - " lux.Clause(\"PctForeclosured\"),\n", - " lux.Clause(\"City=Crofton\"),\n", - "]\n", - "df\n", - "# vis = df.recommendation[\"Similarity\"][0]\n", - "# vis\n", - "# vis.data" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "18dbaa0c77d940548a45653e8b4dac4b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4a05513659e7486a8aa8591de35f789d", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "df = pd.DataFrame({'nPts': {0: 49999, 1: 71174, 2: 101317, 3: 144224, 4: 205303, 5: 292249, 6: 416016, 7: 592198, 8: 842993, 9: 1200000}, 't_heatmap': {0: 0.15121674537658691, 1: 0.1811518669128418, 2: 0.2179429531097412, 3: 0.2787730693817139, 4: 0.3973350524902344, 5: 0.4233138561248779, 6: 0.580251932144165, 7: 0.7928099632263184, 8: 1.0876789093017578, 9: 1.6242818832397459}, 't_color_heatmap': {0: 0.14242982864379886, 1: 0.18866705894470212, 2: 0.1566781997680664, 3: 0.16737699508666992, 4: 0.19900894165039065, 5: 0.2701129913330078, 6: 0.2533812522888184, 7: 0.37183785438537603, 8: 0.3830866813659668, 9: 0.39321017265319824}, 't_bar': {0: 0.01940608024597168, 1: 0.02618718147277832, 2: 0.024693727493286133, 3: 0.029685020446777344, 4: 0.03471803665161133, 5: 0.04173588752746582, 6: 0.04706382751464844, 7: 0.0667569637298584, 8: 0.08260798454284668, 9: 0.1006929874420166}, 't_cbar': {0: 0.04185795783996582, 1: 0.050965070724487305, 2: 0.052091121673583984, 3: 0.0610501766204834, 4: 0.07504606246948242, 5: 0.09924101829528807, 6: 0.10392117500305176, 7: 0.13044309616088867, 8: 0.18137121200561526, 9: 0.2069528102874756}, 't_hist': {0: 0.01846003532409668, 1: 0.018136978149414062, 2: 0.018748998641967773, 3: 0.01876473426818848, 4: 0.02434706687927246, 5: 0.025368213653564453, 6: 0.02530217170715332, 7: 0.02823114395141602, 8: 0.029034852981567383, 9: 0.034781217575073235}, 't_scatter': {0: 0.8179378509521484, 1: 1.0982017517089844, 2: 1.4875690937042236, 3: 2.146117925643921, 4: 3.1123709678649902, 5: 3.92416787147522, 6: 6.097048044204713, 7: 8.803220987319945, 8: 12.054464101791382, 9: 17.740845680236816}, 't_color_scatter': {0: 1.3474130630493164, 1: 1.7953579425811768, 2: 2.6268541812896733, 3: 3.646371126174927, 4: 4.901940107345581, 5: 6.974237203598023, 6: 10.197483777999876, 7: 14.134275913238525, 8: 21.13951110839844, 9: 27.127063989639282}})\n", - "# df['time'] = pd.to_datetime(df['time'], format='')\n", - "# df.set_data_type({'time':'quantitative'})\n", - "\n", - "pdf = df.melt(id_vars=[\"nPts\"],value_vars=['t_heatmap', 't_color_heatmap', 't_bar', 't_cbar', 't_hist','t_scatter', 't_color_scatter'], var_name=\"type\", value_name='t')\n", - "pdf\n", - "# pdf.dtypes\n", - "pdf.set_data_type({'time':'quantitative'})\n", - "pdf\n", - "# pdf.columns\n", - "# from lux.vis.VisList import VisList\n", - "# vis = VisList([i for i in pdf.columns], pdf)\n", - "# vis" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/caitlynachen/Desktop/frontendlux/tutorial-env/lib/python3.8/site-packages/lux_api-0.2.3-py3.8.egg/lux/executor/PandasExecutor.py:402: UserWarning:\n", - "Lux detects that the attribute 'Year' may be temporal.\n", - "To display visualizations for these attributes accurately, please convert temporal attributes to Pandas Datetime objects using the pd.to_datetime function and provide a 'format' parameter to specify the datetime format of the attribute.\n", - "For example, you can convert a year-only attribute (e.g., 1998, 1971, 1982) to Datetime type by specifying the `format` as '%Y'.\n", - "\n", - "Here is a starter template that you can use for converting the temporal fields:\n", - "\tdf['Year'] = pd.to_datetime(df['Year'], format='')\n", - "\n", - "See more at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html\n", - "If Year is not a temporal attribute, please use override Lux's automatically detected type:\n", - "\tdf.set_data_type({'Year':'quantitative'})\n" - ] - }, - { - "data": { - "text/plain": [ - "[dtype('O'), dtype('O'), dtype('int64'), dtype('O'), dtype(']}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.recommendation" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a8055bad9484cbbab861000b3af8f28", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Button(description='Toggle Pandas/Lux', layout=Layout(top='5px', width='140px'), style=ButtonStyle())" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f69914ca65fd48538340836781da8d79", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "04665be8b2f04ae69ef4a0be5cfb339b", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "LuxWidget(current_vis={'config': 'iVBORw0KGgoAAAANSUhEUgAAAUQAAAEgCAYAAADMjwqKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.exported[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# import altair as alt\n", - "# alt.Chart(df).mark_bar().encode(\n", - "# x=alt.X(longtitle, axis=alt.Axis(title=longtitle)),\n", - "# y=alt.Y(df., axis=alt.Axis(title=\"Record\"))\n", - "# )\n", - "import altair as alt\n", - "import pandas as pd\n", - "source = pd.DataFrame({\n", - " 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],\n", - " 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]\n", - "})\n", - "chart = alt.Chart(source).mark_bar().encode(\n", - " x=alt.X('a', axis=alt.Axis(labelOverlap=True)),\n", - " y=alt.Y('b')\n", - ")\n", - "chart.encoding.x.axis.title = 'a...'\n", - "chart" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "longtitle = 'Students across social identities have meaningful opportunities to demonstrate or access the above learning opportunities.'\n", - "longtitle2 = 'The teacher provides supports, encouragement, and opportunities equally well for all students in the class, across all sub-groups.'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.columns = df.columns.str.replace(\".\",\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.rename(columns={longtitle:longtitle[:-1],longtitle2:longtitle2[:-1]})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df.data_model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/lux/_config/config.py b/lux/_config/config.py index 519f1f5d..eb103ad7 100644 --- a/lux/_config/config.py +++ b/lux/_config/config.py @@ -55,8 +55,7 @@ def topk(self, k: Union[int, bool]): self._topk = k else: warnings.warn( - "Parameter to lux.config.topk must be an integer or a boolean.", - stacklevel=2, + "Parameter to lux.config.topk must be an integer or a boolean.", stacklevel=2, ) @property @@ -99,8 +98,7 @@ def pandas_fallback(self, fallback: bool) -> None: self._pandas_fallback = fallback else: warnings.warn( - "The flag for Pandas fallback must be a boolean.", - stacklevel=2, + "The flag for Pandas fallback must be a boolean.", stacklevel=2, ) @property @@ -120,8 +118,7 @@ def interestingness_fallback(self, fallback: bool) -> None: self._interestingness_fallback = fallback else: warnings.warn( - "The flag for interestingness fallback must be a boolean.", - stacklevel=2, + "The flag for interestingness fallback must be a boolean.", stacklevel=2, ) @property @@ -147,8 +144,7 @@ def sampling_cap(self, sample_number: int) -> None: self._sampling_cap = sample_number else: warnings.warn( - "The cap on the number samples must be an integer.", - stacklevel=2, + "The cap on the number samples must be an integer.", stacklevel=2, ) @property @@ -176,8 +172,7 @@ def sampling_start(self, sample_number: int) -> None: self._sampling_start = sample_number else: warnings.warn( - "The sampling starting point must be an integer.", - stacklevel=2, + "The sampling starting point must be an integer.", stacklevel=2, ) @property @@ -202,8 +197,7 @@ def sampling(self, sample_flag: bool) -> None: self._sampling_flag = sample_flag else: warnings.warn( - "The flag for sampling must be a boolean.", - stacklevel=2, + "The flag for sampling must be a boolean.", stacklevel=2, ) @property @@ -228,8 +222,7 @@ def heatmap(self, heatmap_flag: bool) -> None: self._heatmap_flag = heatmap_flag else: warnings.warn( - "The flag for enabling/disabling heatmaps must be a boolean.", - stacklevel=2, + "The flag for enabling/disabling heatmaps must be a boolean.", stacklevel=2, ) @property diff --git a/lux/action/generalize.py b/lux/action/generalize.py index 385891d4..84504132 100644 --- a/lux/action/generalize.py +++ b/lux/action/generalize.py @@ -78,12 +78,7 @@ def generalize(ldf): for clause in filters: # new_spec = ldf._intent.copy() # new_spec.remove_column_from_spec(new_spec.attribute) - temp_vis = Vis( - ldf.current_vis[0]._inferred_intent.copy(), - source=ldf, - title="Overall", - score=0, - ) + temp_vis = Vis(ldf.current_vis[0]._inferred_intent.copy(), source=ldf, title="Overall", score=0,) temp_vis.remove_filter_from_spec(clause.value) output.append(temp_vis) diff --git a/lux/action/row_group.py b/lux/action/row_group.py index 5555c01f..7407ab5b 100644 --- a/lux/action/row_group.py +++ b/lux/action/row_group.py @@ -50,13 +50,7 @@ def row_group(ldf): # rowdf.cardinality["index"]=len(rowdf) # if isinstance(ldf.columns,pd.DatetimeIndex): # rowdf.data_type_lookup[dim_name]="temporal" - vis = Vis( - [ - dim_name, - lux.Clause(row.name, data_model="measure", aggregation=None), - ], - rowdf, - ) + vis = Vis([dim_name, lux.Clause(row.name, data_model="measure", aggregation=None),], rowdf,) collection.append(vis) vlst = VisList(collection) # Note that we are not computing interestingness score here because we want to preserve the arrangement of the aggregated data diff --git a/lux/core/frame.py b/lux/core/frame.py index 215cf529..f149ff55 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -364,8 +364,7 @@ def get_SQL_cardinality(self): cardinality = {} for attr in list(self.columns): card_query = pd.read_sql( - f"SELECT Count(Distinct({attr})) FROM {self.table_name}", - lux.config.SQLconnection, + f"SELECT Count(Distinct({attr})) FROM {self.table_name}", lux.config.SQLconnection, ) cardinality[attr] = list(card_query["count"])[0] self.cardinality = cardinality @@ -374,8 +373,7 @@ def get_SQL_unique_values(self): unique_vals = {} for attr in list(self.columns): unique_query = pd.read_sql( - f"SELECT Distinct({attr}) FROM {self.table_name}", - lux.config.SQLconnection, + f"SELECT Distinct({attr}) FROM {self.table_name}", lux.config.SQLconnection, ) unique_vals[attr] = list(unique_query[attr]) self.unique_values = unique_vals @@ -428,7 +426,7 @@ def _append_rec(self, rec_infolist, recommendations: Dict): def show_all_column_vis(self): quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] - if len(quantitative_columns) == 2 or len(quantitative_columns) == 3: + if (len(quantitative_columns) == 2 or len(quantitative_columns) == 3) and self._intent == []: self.current_vis = VisList([i for i in self.columns], self) def maintain_recs(self, is_series="DataFrame"): @@ -582,8 +580,7 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: exported_vis = VisList( list( map( - self._recommendation[export_action].__getitem__, - exported_vis_lst[export_action], + self._recommendation[export_action].__getitem__, exported_vis_lst[export_action], ) ) ) @@ -654,8 +651,7 @@ def _ipython_display_(self): self._widget.observe(self.set_intent_on_click, names="selectedIntentIndex") button = widgets.Button( - description="Toggle Pandas/Lux", - layout=widgets.Layout(width="140px", top="5px"), + description="Toggle Pandas/Lux", layout=widgets.Layout(width="140px", top="5px"), ) self.output = widgets.Output() display(button, self.output) diff --git a/lux/core/series.py b/lux/core/series.py index a5e2defd..7325849d 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -153,8 +153,7 @@ def _ipython_display_(self): # box = widgets.Box(layout=widgets.Layout(display='inline')) button = widgets.Button( - description="Toggle Pandas/Lux", - layout=widgets.Layout(width="140px", top="5px"), + description="Toggle Pandas/Lux", layout=widgets.Layout(width="140px", top="5px"), ) ldf.output = widgets.Output() # box.children = [button,output] diff --git a/lux/executor/PandasExecutor.py b/lux/executor/PandasExecutor.py index 35115781..f6cf1ebd 100644 --- a/lux/executor/PandasExecutor.py +++ b/lux/executor/PandasExecutor.py @@ -217,10 +217,7 @@ def execute_aggregate(vis: Vis, isFiltered=True): } ) vis._vis_data = vis.data.merge( - df, - on=[columns[0], columns[1]], - how="right", - suffixes=["", "_right"], + df, on=[columns[0], columns[1]], how="right", suffixes=["", "_right"], ) for col in columns[2:]: vis.data[col] = vis.data[col].fillna(0) # Triggers __setitem__ @@ -368,10 +365,7 @@ def execute_2D_binning(vis: Vis): if color_attr.data_type == "nominal": # Compute mode and count. Mode aggregates each cell by taking the majority vote for the category variable. In cases where there is ties across categories, pick the first item (.iat[0]) result = groups.agg( - [ - ("count", "count"), - (color_attr.attribute, lambda x: pd.Series.mode(x).iat[0]), - ] + [("count", "count"), (color_attr.attribute, lambda x: pd.Series.mode(x).iat[0]),] ).reset_index() elif color_attr.data_type == "quantitative": # Compute the average of all values in the bin diff --git a/lux/executor/SQLExecutor.py b/lux/executor/SQLExecutor.py index 6fdab393..d9d2438b 100644 --- a/lux/executor/SQLExecutor.py +++ b/lux/executor/SQLExecutor.py @@ -161,13 +161,11 @@ def execute_binning(vis: Vis, ldf: LuxDataFrame): else: bin_centers = np.array([(attr_min + attr_min + bin_width) / 2]) bin_centers = np.append( - bin_centers, - np.mean(np.vstack([upper_edges[0:-1], upper_edges[1:]]), axis=0), + bin_centers, np.mean(np.vstack([upper_edges[0:-1], upper_edges[1:]]), axis=0), ) if attr_type == int: bin_centers = np.append( - bin_centers, - math.ceil((upper_edges[len(upper_edges) - 1] + attr_max) / 2), + bin_centers, math.ceil((upper_edges[len(upper_edges) - 1] + attr_max) / 2), ) else: bin_centers = np.append(bin_centers, (upper_edges[len(upper_edges) - 1] + attr_max) / 2) diff --git a/lux/interestingness/interestingness.py b/lux/interestingness/interestingness.py index 4eb61fe7..ffa0756b 100644 --- a/lux/interestingness/interestingness.py +++ b/lux/interestingness/interestingness.py @@ -199,11 +199,7 @@ def weighted_correlation(x, y, w): def deviation_from_overall( - vis: Vis, - ldf: LuxDataFrame, - filter_specs: list, - msr_attribute: str, - exclude_nan: bool = True, + vis: Vis, ldf: LuxDataFrame, filter_specs: list, msr_attribute: str, exclude_nan: bool = True, ) -> int: """ Difference in bar chart/histogram shape from overall chart diff --git a/lux/interestingness/similarity.py b/lux/interestingness/similarity.py index 8d810909..017b97b5 100644 --- a/lux/interestingness/similarity.py +++ b/lux/interestingness/similarity.py @@ -68,8 +68,7 @@ def interpolate(vis, length): yVals[count - 1] + (interpolated_x - xVals[count - 1]) / x_diff * yDiff ) vis.data = pd.DataFrame( - list(zip(interpolated_x_vals, interpolated_y_vals)), - columns=[xAxis, yAxis], + list(zip(interpolated_x_vals, interpolated_y_vals)), columns=[xAxis, yAxis], ) diff --git a/lux/processor/Compiler.py b/lux/processor/Compiler.py index 96d95d10..85c49cfb 100644 --- a/lux/processor/Compiler.py +++ b/lux/processor/Compiler.py @@ -281,10 +281,7 @@ def line_or_bar_or_geo(ldf, dimension: Clause, measure: Clause): # ShowMe logic + additional heuristics # count_col = Clause( attribute="count()", data_model="measure") count_col = Clause( - attribute="Record", - aggregation="count", - data_model="measure", - data_type="quantitative", + attribute="Record", aggregation="count", data_model="measure", data_type="quantitative", ) auto_channel = {} if ndim == 0 and nmsr == 1: @@ -475,9 +472,7 @@ def populate_wildcard_options(_inferred_intent: List[Clause], ldf: LuxDataFrame) options = ldf.unique_values[attr] specInd = _inferred_intent.index(clause) _inferred_intent[specInd] = Clause( - attribute=clause.attribute, - filter_op="=", - value=list(options), + attribute=clause.attribute, filter_op="=", value=list(options), ) else: options.extend(convert_to_list(clause.value)) diff --git a/lux/vislib/altair/AltairRenderer.py b/lux/vislib/altair/AltairRenderer.py index 6c8ddae2..ac974f15 100644 --- a/lux/vislib/altair/AltairRenderer.py +++ b/lux/vislib/altair/AltairRenderer.py @@ -129,8 +129,7 @@ def create_vis(self, vis, standalone=True): found_variable = "df" if standalone: chart.code = chart.code.replace( - "placeholder_variable", - f"pd.DataFrame({str(vis.data.to_dict())})", + "placeholder_variable", f"pd.DataFrame({str(vis.data.to_dict())})", ) else: # TODO: Placeholder (need to read dynamically via locals()) diff --git a/lux/vislib/altair/Choropleth.py b/lux/vislib/altair/Choropleth.py index 37bf8695..ceefe029 100644 --- a/lux/vislib/altair/Choropleth.py +++ b/lux/vislib/altair/Choropleth.py @@ -68,9 +68,7 @@ def initialize_chart(self): points = ( alt.Chart(geo_map) .mark_geoshape() - .encode( - color=f"{str(y_attr.attribute)}:Q", - ) + .encode(color=f"{str(y_attr.attribute)}:Q",) .transform_lookup( lookup="id", from_=alt.LookupData(self.data, str(x_attr.attribute), [str(y_attr.attribute)]), diff --git a/lux/vislib/altair/Heatmap.py b/lux/vislib/altair/Heatmap.py index f83a3bbb..2f743b32 100644 --- a/lux/vislib/altair/Heatmap.py +++ b/lux/vislib/altair/Heatmap.py @@ -71,10 +71,7 @@ def initialize_chart(self): ), y2=alt.Y2("yBinEnd"), opacity=alt.Opacity( - "count", - type="quantitative", - scale=alt.Scale(type="log"), - legend=None, + "count", type="quantitative", scale=alt.Scale(type="log"), legend=None, ), ) ) diff --git a/tests/test_action.py b/tests/test_action.py index 5e22938c..e6a6c6af 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -184,8 +184,7 @@ def test_year_filter_value(global_var): lambda vis: len( list( filter( - lambda clause: clause.value != "" and clause.attribute == "Year", - vis._intent, + lambda clause: clause.value != "" and clause.attribute == "Year", vis._intent, ) ) ) @@ -215,16 +214,10 @@ def test_similarity(global_var): ranked_list = df.recommendation["Similarity"] japan_vis = list( - filter( - lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Japan", - ranked_list, - ) + filter(lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Japan", ranked_list,) )[0] europe_vis = list( - filter( - lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Europe", - ranked_list, - ) + filter(lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Europe", ranked_list,) )[0] assert japan_vis.score > europe_vis.score df.clear_intent() @@ -247,16 +240,10 @@ def test_similarity2(): ranked_list = df.recommendation["Similarity"] morrisville_vis = list( - filter( - lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Morrisville", - ranked_list, - ) + filter(lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Morrisville", ranked_list,) )[0] watertown_vis = list( - filter( - lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Watertown", - ranked_list, - ) + filter(lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Watertown", ranked_list,) )[0] assert morrisville_vis.score > watertown_vis.score diff --git a/tests/test_compiler.py b/tests/test_compiler.py index 76e7034d..de625c74 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -113,10 +113,7 @@ def test_underspecified_vis_collection_zval(global_var): # check if the number of charts is correct df = pytest.car_df vlst = VisList( - [ - lux.Clause(attribute="Origin", filter_op="=", value="?"), - lux.Clause(attribute="MilesPerGal"), - ], + [lux.Clause(attribute="Origin", filter_op="=", value="?"), lux.Clause(attribute="MilesPerGal"),], df, ) assert len(vlst) == 3 @@ -189,10 +186,7 @@ def test_specified_channel_enforced_vis_collection(global_var): df = pytest.car_df # change pandas dtype for the column "Year" to datetype df["Year"] = pd.to_datetime(df["Year"], format="%Y") - visList = VisList( - [lux.Clause(attribute="?"), lux.Clause(attribute="MilesPerGal", channel="x")], - df, - ) + visList = VisList([lux.Clause(attribute="?"), lux.Clause(attribute="MilesPerGal", channel="x")], df,) for vis in visList: check_attribute_on_channel(vis, "MilesPerGal", "x") @@ -207,22 +201,13 @@ def test_autoencoding_scatter(global_var): check_attribute_on_channel(vis, "Weight", "y") # Partial channel specified - vis = Vis( - [ - lux.Clause(attribute="MilesPerGal", channel="y"), - lux.Clause(attribute="Weight"), - ], - df, - ) + vis = Vis([lux.Clause(attribute="MilesPerGal", channel="y"), lux.Clause(attribute="Weight"),], df,) check_attribute_on_channel(vis, "MilesPerGal", "y") check_attribute_on_channel(vis, "Weight", "x") # Full channel specified vis = Vis( - [ - lux.Clause(attribute="MilesPerGal", channel="y"), - lux.Clause(attribute="Weight", channel="x"), - ], + [lux.Clause(attribute="MilesPerGal", channel="y"), lux.Clause(attribute="Weight", channel="x"),], df, ) check_attribute_on_channel(vis, "MilesPerGal", "y") @@ -261,22 +246,13 @@ def test_autoencoding_line_chart(global_var): check_attribute_on_channel(vis, "Acceleration", "y") # Partial channel specified - vis = Vis( - [ - lux.Clause(attribute="Year", channel="y"), - lux.Clause(attribute="Acceleration"), - ], - df, - ) + vis = Vis([lux.Clause(attribute="Year", channel="y"), lux.Clause(attribute="Acceleration"),], df,) check_attribute_on_channel(vis, "Year", "y") check_attribute_on_channel(vis, "Acceleration", "x") # Full channel specified vis = Vis( - [ - lux.Clause(attribute="Year", channel="y"), - lux.Clause(attribute="Acceleration", channel="x"), - ], + [lux.Clause(attribute="Year", channel="y"), lux.Clause(attribute="Acceleration", channel="x"),], df, ) check_attribute_on_channel(vis, "Year", "y") @@ -345,10 +321,7 @@ def test_populate_options(global_var): assert list_equal(list(col_set), list(df.columns)) df.set_intent( - [ - lux.Clause(attribute="?", data_model="measure"), - lux.Clause(attribute="MilesPerGal"), - ] + [lux.Clause(attribute="?", data_model="measure"), lux.Clause(attribute="MilesPerGal"),] ) df._ipython_display_() col_set = set() @@ -356,8 +329,7 @@ def test_populate_options(global_var): for clause in specOptions: col_set.add(clause.attribute) assert list_equal( - list(col_set), - ["Acceleration", "Weight", "Horsepower", "MilesPerGal", "Displacement"], + list(col_set), ["Acceleration", "Weight", "Horsepower", "MilesPerGal", "Displacement"], ) df.clear_intent() @@ -367,10 +339,7 @@ def test_remove_all_invalid(global_var): df["Year"] = pd.to_datetime(df["Year"], format="%Y") # with pytest.warns(UserWarning,match="duplicate attribute specified in the intent"): df.set_intent( - [ - lux.Clause(attribute="Origin", filter_op="=", value="USA"), - lux.Clause(attribute="Origin"), - ] + [lux.Clause(attribute="Origin", filter_op="=", value="USA"), lux.Clause(attribute="Origin"),] ) df._ipython_display_() assert len(df.current_vis) == 0 diff --git a/tests/test_dates.py b/tests/test_dates.py index d6295b05..4eed2cc3 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -44,10 +44,7 @@ def test_period_selection(global_var): ldf["Year"] = pd.DatetimeIndex(ldf["Year"]).to_period(freq="A") ldf.set_intent( - [ - lux.Clause(attribute=["Horsepower", "Weight", "Acceleration"]), - lux.Clause(attribute="Year"), - ] + [lux.Clause(attribute=["Horsepower", "Weight", "Acceleration"]), lux.Clause(attribute="Year"),] ) lux.config.executor.execute(ldf.current_vis, ldf) diff --git a/tests/test_interestingness.py b/tests/test_interestingness.py index 1dc4f535..df8896e2 100644 --- a/tests/test_interestingness.py +++ b/tests/test_interestingness.py @@ -64,10 +64,7 @@ def test_interestingness_1_0_1(global_var): df["Year"] = pd.to_datetime(df["Year"], format="%Y") df.set_intent( - [ - lux.Clause(attribute="Origin", filter_op="=", value="USA"), - lux.Clause(attribute="Cylinders"), - ] + [lux.Clause(attribute="Origin", filter_op="=", value="USA"), lux.Clause(attribute="Cylinders"),] ) df._ipython_display_() assert df.current_vis[0].score == 0 @@ -124,10 +121,7 @@ def test_interestingness_0_1_1(global_var): df["Year"] = pd.to_datetime(df["Year"], format="%Y") df.set_intent( - [ - lux.Clause(attribute="Origin", filter_op="=", value="?"), - lux.Clause(attribute="MilesPerGal"), - ] + [lux.Clause(attribute="Origin", filter_op="=", value="?"), lux.Clause(attribute="MilesPerGal"),] ) df._ipython_display_() assert interestingness(df.recommendation["Current Vis"][0], df) != None diff --git a/tests/test_pandas_coverage.py b/tests/test_pandas_coverage.py index c1039591..62fde04b 100644 --- a/tests/test_pandas_coverage.py +++ b/tests/test_pandas_coverage.py @@ -173,8 +173,7 @@ def test_groupby_agg_big(global_var): assert len(new_df.cardinality) == 8 year_vis = list( filter( - lambda vis: vis.get_attr_by_attr_name("Year") != [], - new_df.recommendation["Column Groups"], + lambda vis: vis.get_attr_by_attr_name("Year") != [], new_df.recommendation["Column Groups"], ) )[0] assert year_vis.mark == "bar" @@ -182,10 +181,7 @@ def test_groupby_agg_big(global_var): new_df = new_df.T new_df._ipython_display_() year_vis = list( - filter( - lambda vis: vis.get_attr_by_attr_name("Year") != [], - new_df.recommendation["Row Groups"], - ) + filter(lambda vis: vis.get_attr_by_attr_name("Year") != [], new_df.recommendation["Row Groups"],) )[0] assert year_vis.mark == "bar" assert year_vis.get_attr_by_channel("x")[0].attribute == "Year" diff --git a/tests/test_parser.py b/tests/test_parser.py index bac6d45d..1742e680 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -121,7 +121,6 @@ def test_validator_invalid_attribute(global_var): df = pytest.college_df with pytest.raises(KeyError, match="'blah'"): with pytest.warns( - UserWarning, - match="The input attribute 'blah' does not exist in the DataFrame.", + UserWarning, match="The input attribute 'blah' does not exist in the DataFrame.", ): df.intent = ["blah"] diff --git a/tests/test_vis.py b/tests/test_vis.py index 2f7b004a..9525b645 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -153,10 +153,7 @@ def test_vis_list_custom_title_override(global_var): vcLst = [] for attribute in ["Sport", "Year", "Height", "HostRegion", "SportType"]: - vis = Vis( - [lux.Clause("Weight"), lux.Clause(attribute)], - title="overriding dummy title", - ) + vis = Vis([lux.Clause("Weight"), lux.Clause(attribute)], title="overriding dummy title",) vcLst.append(vis) vlist = VisList(vcLst, df) for v in vlist: @@ -538,6 +535,7 @@ def test_all_column_current_vis(): df._ipython_display_() assert df.current_vis != None + def test_all_column_current_vis_filter(): lux.config.plotting_backend = "matplotlib" df = pytest.car_df @@ -548,12 +546,13 @@ def test_all_column_current_vis_filter(): df = df[["Year", "Displacement", "Origin"]] df._ipython_display_() + def test_intent_override_all_column(): lux.config.plotting_backend = "matplotlib" df = pytest.car_df df = df[["Year", "Displacement"]] df.intent = ["Year"] df._ipython_display_() - assert df.current_vis != None + current_vis_code = df.current_vis[0].to_matplotlib_code() + assert "ax.set_ylabel(\'Number of Records\')" in current_vis_code, "All column not overriden by intent" lux.config.plotting_backend = "altair" - From 66b0f44b33d0e5d50406b8fe302f47fe9b3fa1c5 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 22:15:01 -0700 Subject: [PATCH 33/36] black --- lux/_config/config.py | 21 +++++++---- lux/action/generalize.py | 7 +++- lux/action/row_group.py | 8 ++++- lux/core/frame.py | 12 ++++--- lux/core/series.py | 3 +- lux/executor/PandasExecutor.py | 10 ++++-- lux/executor/SQLExecutor.py | 6 ++-- lux/interestingness/interestingness.py | 6 +++- lux/interestingness/similarity.py | 3 +- lux/processor/Compiler.py | 9 +++-- lux/vislib/altair/AltairRenderer.py | 3 +- lux/vislib/altair/Choropleth.py | 4 ++- lux/vislib/altair/Heatmap.py | 5 ++- tests/test_action.py | 23 +++++++++--- tests/test_compiler.py | 49 +++++++++++++++++++++----- tests/test_dates.py | 5 ++- tests/test_interestingness.py | 10 ++++-- tests/test_pandas_coverage.py | 8 +++-- tests/test_parser.py | 3 +- tests/test_vis.py | 7 ++-- 20 files changed, 155 insertions(+), 47 deletions(-) diff --git a/lux/_config/config.py b/lux/_config/config.py index eb103ad7..519f1f5d 100644 --- a/lux/_config/config.py +++ b/lux/_config/config.py @@ -55,7 +55,8 @@ def topk(self, k: Union[int, bool]): self._topk = k else: warnings.warn( - "Parameter to lux.config.topk must be an integer or a boolean.", stacklevel=2, + "Parameter to lux.config.topk must be an integer or a boolean.", + stacklevel=2, ) @property @@ -98,7 +99,8 @@ def pandas_fallback(self, fallback: bool) -> None: self._pandas_fallback = fallback else: warnings.warn( - "The flag for Pandas fallback must be a boolean.", stacklevel=2, + "The flag for Pandas fallback must be a boolean.", + stacklevel=2, ) @property @@ -118,7 +120,8 @@ def interestingness_fallback(self, fallback: bool) -> None: self._interestingness_fallback = fallback else: warnings.warn( - "The flag for interestingness fallback must be a boolean.", stacklevel=2, + "The flag for interestingness fallback must be a boolean.", + stacklevel=2, ) @property @@ -144,7 +147,8 @@ def sampling_cap(self, sample_number: int) -> None: self._sampling_cap = sample_number else: warnings.warn( - "The cap on the number samples must be an integer.", stacklevel=2, + "The cap on the number samples must be an integer.", + stacklevel=2, ) @property @@ -172,7 +176,8 @@ def sampling_start(self, sample_number: int) -> None: self._sampling_start = sample_number else: warnings.warn( - "The sampling starting point must be an integer.", stacklevel=2, + "The sampling starting point must be an integer.", + stacklevel=2, ) @property @@ -197,7 +202,8 @@ def sampling(self, sample_flag: bool) -> None: self._sampling_flag = sample_flag else: warnings.warn( - "The flag for sampling must be a boolean.", stacklevel=2, + "The flag for sampling must be a boolean.", + stacklevel=2, ) @property @@ -222,7 +228,8 @@ def heatmap(self, heatmap_flag: bool) -> None: self._heatmap_flag = heatmap_flag else: warnings.warn( - "The flag for enabling/disabling heatmaps must be a boolean.", stacklevel=2, + "The flag for enabling/disabling heatmaps must be a boolean.", + stacklevel=2, ) @property diff --git a/lux/action/generalize.py b/lux/action/generalize.py index 84504132..385891d4 100644 --- a/lux/action/generalize.py +++ b/lux/action/generalize.py @@ -78,7 +78,12 @@ def generalize(ldf): for clause in filters: # new_spec = ldf._intent.copy() # new_spec.remove_column_from_spec(new_spec.attribute) - temp_vis = Vis(ldf.current_vis[0]._inferred_intent.copy(), source=ldf, title="Overall", score=0,) + temp_vis = Vis( + ldf.current_vis[0]._inferred_intent.copy(), + source=ldf, + title="Overall", + score=0, + ) temp_vis.remove_filter_from_spec(clause.value) output.append(temp_vis) diff --git a/lux/action/row_group.py b/lux/action/row_group.py index 7407ab5b..5555c01f 100644 --- a/lux/action/row_group.py +++ b/lux/action/row_group.py @@ -50,7 +50,13 @@ def row_group(ldf): # rowdf.cardinality["index"]=len(rowdf) # if isinstance(ldf.columns,pd.DatetimeIndex): # rowdf.data_type_lookup[dim_name]="temporal" - vis = Vis([dim_name, lux.Clause(row.name, data_model="measure", aggregation=None),], rowdf,) + vis = Vis( + [ + dim_name, + lux.Clause(row.name, data_model="measure", aggregation=None), + ], + rowdf, + ) collection.append(vis) vlst = VisList(collection) # Note that we are not computing interestingness score here because we want to preserve the arrangement of the aggregated data diff --git a/lux/core/frame.py b/lux/core/frame.py index f149ff55..6527f311 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -364,7 +364,8 @@ def get_SQL_cardinality(self): cardinality = {} for attr in list(self.columns): card_query = pd.read_sql( - f"SELECT Count(Distinct({attr})) FROM {self.table_name}", lux.config.SQLconnection, + f"SELECT Count(Distinct({attr})) FROM {self.table_name}", + lux.config.SQLconnection, ) cardinality[attr] = list(card_query["count"])[0] self.cardinality = cardinality @@ -373,7 +374,8 @@ def get_SQL_unique_values(self): unique_vals = {} for attr in list(self.columns): unique_query = pd.read_sql( - f"SELECT Distinct({attr}) FROM {self.table_name}", lux.config.SQLconnection, + f"SELECT Distinct({attr}) FROM {self.table_name}", + lux.config.SQLconnection, ) unique_vals[attr] = list(unique_query[attr]) self.unique_values = unique_vals @@ -580,7 +582,8 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: exported_vis = VisList( list( map( - self._recommendation[export_action].__getitem__, exported_vis_lst[export_action], + self._recommendation[export_action].__getitem__, + exported_vis_lst[export_action], ) ) ) @@ -651,7 +654,8 @@ def _ipython_display_(self): self._widget.observe(self.set_intent_on_click, names="selectedIntentIndex") button = widgets.Button( - description="Toggle Pandas/Lux", layout=widgets.Layout(width="140px", top="5px"), + description="Toggle Pandas/Lux", + layout=widgets.Layout(width="140px", top="5px"), ) self.output = widgets.Output() display(button, self.output) diff --git a/lux/core/series.py b/lux/core/series.py index 7325849d..a5e2defd 100644 --- a/lux/core/series.py +++ b/lux/core/series.py @@ -153,7 +153,8 @@ def _ipython_display_(self): # box = widgets.Box(layout=widgets.Layout(display='inline')) button = widgets.Button( - description="Toggle Pandas/Lux", layout=widgets.Layout(width="140px", top="5px"), + description="Toggle Pandas/Lux", + layout=widgets.Layout(width="140px", top="5px"), ) ldf.output = widgets.Output() # box.children = [button,output] diff --git a/lux/executor/PandasExecutor.py b/lux/executor/PandasExecutor.py index f6cf1ebd..35115781 100644 --- a/lux/executor/PandasExecutor.py +++ b/lux/executor/PandasExecutor.py @@ -217,7 +217,10 @@ def execute_aggregate(vis: Vis, isFiltered=True): } ) vis._vis_data = vis.data.merge( - df, on=[columns[0], columns[1]], how="right", suffixes=["", "_right"], + df, + on=[columns[0], columns[1]], + how="right", + suffixes=["", "_right"], ) for col in columns[2:]: vis.data[col] = vis.data[col].fillna(0) # Triggers __setitem__ @@ -365,7 +368,10 @@ def execute_2D_binning(vis: Vis): if color_attr.data_type == "nominal": # Compute mode and count. Mode aggregates each cell by taking the majority vote for the category variable. In cases where there is ties across categories, pick the first item (.iat[0]) result = groups.agg( - [("count", "count"), (color_attr.attribute, lambda x: pd.Series.mode(x).iat[0]),] + [ + ("count", "count"), + (color_attr.attribute, lambda x: pd.Series.mode(x).iat[0]), + ] ).reset_index() elif color_attr.data_type == "quantitative": # Compute the average of all values in the bin diff --git a/lux/executor/SQLExecutor.py b/lux/executor/SQLExecutor.py index d9d2438b..6fdab393 100644 --- a/lux/executor/SQLExecutor.py +++ b/lux/executor/SQLExecutor.py @@ -161,11 +161,13 @@ def execute_binning(vis: Vis, ldf: LuxDataFrame): else: bin_centers = np.array([(attr_min + attr_min + bin_width) / 2]) bin_centers = np.append( - bin_centers, np.mean(np.vstack([upper_edges[0:-1], upper_edges[1:]]), axis=0), + bin_centers, + np.mean(np.vstack([upper_edges[0:-1], upper_edges[1:]]), axis=0), ) if attr_type == int: bin_centers = np.append( - bin_centers, math.ceil((upper_edges[len(upper_edges) - 1] + attr_max) / 2), + bin_centers, + math.ceil((upper_edges[len(upper_edges) - 1] + attr_max) / 2), ) else: bin_centers = np.append(bin_centers, (upper_edges[len(upper_edges) - 1] + attr_max) / 2) diff --git a/lux/interestingness/interestingness.py b/lux/interestingness/interestingness.py index ffa0756b..4eb61fe7 100644 --- a/lux/interestingness/interestingness.py +++ b/lux/interestingness/interestingness.py @@ -199,7 +199,11 @@ def weighted_correlation(x, y, w): def deviation_from_overall( - vis: Vis, ldf: LuxDataFrame, filter_specs: list, msr_attribute: str, exclude_nan: bool = True, + vis: Vis, + ldf: LuxDataFrame, + filter_specs: list, + msr_attribute: str, + exclude_nan: bool = True, ) -> int: """ Difference in bar chart/histogram shape from overall chart diff --git a/lux/interestingness/similarity.py b/lux/interestingness/similarity.py index 017b97b5..8d810909 100644 --- a/lux/interestingness/similarity.py +++ b/lux/interestingness/similarity.py @@ -68,7 +68,8 @@ def interpolate(vis, length): yVals[count - 1] + (interpolated_x - xVals[count - 1]) / x_diff * yDiff ) vis.data = pd.DataFrame( - list(zip(interpolated_x_vals, interpolated_y_vals)), columns=[xAxis, yAxis], + list(zip(interpolated_x_vals, interpolated_y_vals)), + columns=[xAxis, yAxis], ) diff --git a/lux/processor/Compiler.py b/lux/processor/Compiler.py index 85c49cfb..96d95d10 100644 --- a/lux/processor/Compiler.py +++ b/lux/processor/Compiler.py @@ -281,7 +281,10 @@ def line_or_bar_or_geo(ldf, dimension: Clause, measure: Clause): # ShowMe logic + additional heuristics # count_col = Clause( attribute="count()", data_model="measure") count_col = Clause( - attribute="Record", aggregation="count", data_model="measure", data_type="quantitative", + attribute="Record", + aggregation="count", + data_model="measure", + data_type="quantitative", ) auto_channel = {} if ndim == 0 and nmsr == 1: @@ -472,7 +475,9 @@ def populate_wildcard_options(_inferred_intent: List[Clause], ldf: LuxDataFrame) options = ldf.unique_values[attr] specInd = _inferred_intent.index(clause) _inferred_intent[specInd] = Clause( - attribute=clause.attribute, filter_op="=", value=list(options), + attribute=clause.attribute, + filter_op="=", + value=list(options), ) else: options.extend(convert_to_list(clause.value)) diff --git a/lux/vislib/altair/AltairRenderer.py b/lux/vislib/altair/AltairRenderer.py index ac974f15..6c8ddae2 100644 --- a/lux/vislib/altair/AltairRenderer.py +++ b/lux/vislib/altair/AltairRenderer.py @@ -129,7 +129,8 @@ def create_vis(self, vis, standalone=True): found_variable = "df" if standalone: chart.code = chart.code.replace( - "placeholder_variable", f"pd.DataFrame({str(vis.data.to_dict())})", + "placeholder_variable", + f"pd.DataFrame({str(vis.data.to_dict())})", ) else: # TODO: Placeholder (need to read dynamically via locals()) diff --git a/lux/vislib/altair/Choropleth.py b/lux/vislib/altair/Choropleth.py index ceefe029..37bf8695 100644 --- a/lux/vislib/altair/Choropleth.py +++ b/lux/vislib/altair/Choropleth.py @@ -68,7 +68,9 @@ def initialize_chart(self): points = ( alt.Chart(geo_map) .mark_geoshape() - .encode(color=f"{str(y_attr.attribute)}:Q",) + .encode( + color=f"{str(y_attr.attribute)}:Q", + ) .transform_lookup( lookup="id", from_=alt.LookupData(self.data, str(x_attr.attribute), [str(y_attr.attribute)]), diff --git a/lux/vislib/altair/Heatmap.py b/lux/vislib/altair/Heatmap.py index 2f743b32..f83a3bbb 100644 --- a/lux/vislib/altair/Heatmap.py +++ b/lux/vislib/altair/Heatmap.py @@ -71,7 +71,10 @@ def initialize_chart(self): ), y2=alt.Y2("yBinEnd"), opacity=alt.Opacity( - "count", type="quantitative", scale=alt.Scale(type="log"), legend=None, + "count", + type="quantitative", + scale=alt.Scale(type="log"), + legend=None, ), ) ) diff --git a/tests/test_action.py b/tests/test_action.py index e6a6c6af..5e22938c 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -184,7 +184,8 @@ def test_year_filter_value(global_var): lambda vis: len( list( filter( - lambda clause: clause.value != "" and clause.attribute == "Year", vis._intent, + lambda clause: clause.value != "" and clause.attribute == "Year", + vis._intent, ) ) ) @@ -214,10 +215,16 @@ def test_similarity(global_var): ranked_list = df.recommendation["Similarity"] japan_vis = list( - filter(lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Japan", ranked_list,) + filter( + lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Japan", + ranked_list, + ) )[0] europe_vis = list( - filter(lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Europe", ranked_list,) + filter( + lambda vis: vis.get_attr_by_attr_name("Origin")[0].value == "Europe", + ranked_list, + ) )[0] assert japan_vis.score > europe_vis.score df.clear_intent() @@ -240,10 +247,16 @@ def test_similarity2(): ranked_list = df.recommendation["Similarity"] morrisville_vis = list( - filter(lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Morrisville", ranked_list,) + filter( + lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Morrisville", + ranked_list, + ) )[0] watertown_vis = list( - filter(lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Watertown", ranked_list,) + filter( + lambda vis: vis.get_attr_by_attr_name("City")[0].value == "Watertown", + ranked_list, + ) )[0] assert morrisville_vis.score > watertown_vis.score diff --git a/tests/test_compiler.py b/tests/test_compiler.py index de625c74..76e7034d 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -113,7 +113,10 @@ def test_underspecified_vis_collection_zval(global_var): # check if the number of charts is correct df = pytest.car_df vlst = VisList( - [lux.Clause(attribute="Origin", filter_op="=", value="?"), lux.Clause(attribute="MilesPerGal"),], + [ + lux.Clause(attribute="Origin", filter_op="=", value="?"), + lux.Clause(attribute="MilesPerGal"), + ], df, ) assert len(vlst) == 3 @@ -186,7 +189,10 @@ def test_specified_channel_enforced_vis_collection(global_var): df = pytest.car_df # change pandas dtype for the column "Year" to datetype df["Year"] = pd.to_datetime(df["Year"], format="%Y") - visList = VisList([lux.Clause(attribute="?"), lux.Clause(attribute="MilesPerGal", channel="x")], df,) + visList = VisList( + [lux.Clause(attribute="?"), lux.Clause(attribute="MilesPerGal", channel="x")], + df, + ) for vis in visList: check_attribute_on_channel(vis, "MilesPerGal", "x") @@ -201,13 +207,22 @@ def test_autoencoding_scatter(global_var): check_attribute_on_channel(vis, "Weight", "y") # Partial channel specified - vis = Vis([lux.Clause(attribute="MilesPerGal", channel="y"), lux.Clause(attribute="Weight"),], df,) + vis = Vis( + [ + lux.Clause(attribute="MilesPerGal", channel="y"), + lux.Clause(attribute="Weight"), + ], + df, + ) check_attribute_on_channel(vis, "MilesPerGal", "y") check_attribute_on_channel(vis, "Weight", "x") # Full channel specified vis = Vis( - [lux.Clause(attribute="MilesPerGal", channel="y"), lux.Clause(attribute="Weight", channel="x"),], + [ + lux.Clause(attribute="MilesPerGal", channel="y"), + lux.Clause(attribute="Weight", channel="x"), + ], df, ) check_attribute_on_channel(vis, "MilesPerGal", "y") @@ -246,13 +261,22 @@ def test_autoencoding_line_chart(global_var): check_attribute_on_channel(vis, "Acceleration", "y") # Partial channel specified - vis = Vis([lux.Clause(attribute="Year", channel="y"), lux.Clause(attribute="Acceleration"),], df,) + vis = Vis( + [ + lux.Clause(attribute="Year", channel="y"), + lux.Clause(attribute="Acceleration"), + ], + df, + ) check_attribute_on_channel(vis, "Year", "y") check_attribute_on_channel(vis, "Acceleration", "x") # Full channel specified vis = Vis( - [lux.Clause(attribute="Year", channel="y"), lux.Clause(attribute="Acceleration", channel="x"),], + [ + lux.Clause(attribute="Year", channel="y"), + lux.Clause(attribute="Acceleration", channel="x"), + ], df, ) check_attribute_on_channel(vis, "Year", "y") @@ -321,7 +345,10 @@ def test_populate_options(global_var): assert list_equal(list(col_set), list(df.columns)) df.set_intent( - [lux.Clause(attribute="?", data_model="measure"), lux.Clause(attribute="MilesPerGal"),] + [ + lux.Clause(attribute="?", data_model="measure"), + lux.Clause(attribute="MilesPerGal"), + ] ) df._ipython_display_() col_set = set() @@ -329,7 +356,8 @@ def test_populate_options(global_var): for clause in specOptions: col_set.add(clause.attribute) assert list_equal( - list(col_set), ["Acceleration", "Weight", "Horsepower", "MilesPerGal", "Displacement"], + list(col_set), + ["Acceleration", "Weight", "Horsepower", "MilesPerGal", "Displacement"], ) df.clear_intent() @@ -339,7 +367,10 @@ def test_remove_all_invalid(global_var): df["Year"] = pd.to_datetime(df["Year"], format="%Y") # with pytest.warns(UserWarning,match="duplicate attribute specified in the intent"): df.set_intent( - [lux.Clause(attribute="Origin", filter_op="=", value="USA"), lux.Clause(attribute="Origin"),] + [ + lux.Clause(attribute="Origin", filter_op="=", value="USA"), + lux.Clause(attribute="Origin"), + ] ) df._ipython_display_() assert len(df.current_vis) == 0 diff --git a/tests/test_dates.py b/tests/test_dates.py index 4eed2cc3..d6295b05 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -44,7 +44,10 @@ def test_period_selection(global_var): ldf["Year"] = pd.DatetimeIndex(ldf["Year"]).to_period(freq="A") ldf.set_intent( - [lux.Clause(attribute=["Horsepower", "Weight", "Acceleration"]), lux.Clause(attribute="Year"),] + [ + lux.Clause(attribute=["Horsepower", "Weight", "Acceleration"]), + lux.Clause(attribute="Year"), + ] ) lux.config.executor.execute(ldf.current_vis, ldf) diff --git a/tests/test_interestingness.py b/tests/test_interestingness.py index df8896e2..1dc4f535 100644 --- a/tests/test_interestingness.py +++ b/tests/test_interestingness.py @@ -64,7 +64,10 @@ def test_interestingness_1_0_1(global_var): df["Year"] = pd.to_datetime(df["Year"], format="%Y") df.set_intent( - [lux.Clause(attribute="Origin", filter_op="=", value="USA"), lux.Clause(attribute="Cylinders"),] + [ + lux.Clause(attribute="Origin", filter_op="=", value="USA"), + lux.Clause(attribute="Cylinders"), + ] ) df._ipython_display_() assert df.current_vis[0].score == 0 @@ -121,7 +124,10 @@ def test_interestingness_0_1_1(global_var): df["Year"] = pd.to_datetime(df["Year"], format="%Y") df.set_intent( - [lux.Clause(attribute="Origin", filter_op="=", value="?"), lux.Clause(attribute="MilesPerGal"),] + [ + lux.Clause(attribute="Origin", filter_op="=", value="?"), + lux.Clause(attribute="MilesPerGal"), + ] ) df._ipython_display_() assert interestingness(df.recommendation["Current Vis"][0], df) != None diff --git a/tests/test_pandas_coverage.py b/tests/test_pandas_coverage.py index 62fde04b..c1039591 100644 --- a/tests/test_pandas_coverage.py +++ b/tests/test_pandas_coverage.py @@ -173,7 +173,8 @@ def test_groupby_agg_big(global_var): assert len(new_df.cardinality) == 8 year_vis = list( filter( - lambda vis: vis.get_attr_by_attr_name("Year") != [], new_df.recommendation["Column Groups"], + lambda vis: vis.get_attr_by_attr_name("Year") != [], + new_df.recommendation["Column Groups"], ) )[0] assert year_vis.mark == "bar" @@ -181,7 +182,10 @@ def test_groupby_agg_big(global_var): new_df = new_df.T new_df._ipython_display_() year_vis = list( - filter(lambda vis: vis.get_attr_by_attr_name("Year") != [], new_df.recommendation["Row Groups"],) + filter( + lambda vis: vis.get_attr_by_attr_name("Year") != [], + new_df.recommendation["Row Groups"], + ) )[0] assert year_vis.mark == "bar" assert year_vis.get_attr_by_channel("x")[0].attribute == "Year" diff --git a/tests/test_parser.py b/tests/test_parser.py index 1742e680..bac6d45d 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -121,6 +121,7 @@ def test_validator_invalid_attribute(global_var): df = pytest.college_df with pytest.raises(KeyError, match="'blah'"): with pytest.warns( - UserWarning, match="The input attribute 'blah' does not exist in the DataFrame.", + UserWarning, + match="The input attribute 'blah' does not exist in the DataFrame.", ): df.intent = ["blah"] diff --git a/tests/test_vis.py b/tests/test_vis.py index 9525b645..74f8a5a0 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -153,7 +153,10 @@ def test_vis_list_custom_title_override(global_var): vcLst = [] for attribute in ["Sport", "Year", "Height", "HostRegion", "SportType"]: - vis = Vis([lux.Clause("Weight"), lux.Clause(attribute)], title="overriding dummy title",) + vis = Vis( + [lux.Clause("Weight"), lux.Clause(attribute)], + title="overriding dummy title", + ) vcLst.append(vis) vlist = VisList(vcLst, df) for v in vlist: @@ -554,5 +557,5 @@ def test_intent_override_all_column(): df.intent = ["Year"] df._ipython_display_() current_vis_code = df.current_vis[0].to_matplotlib_code() - assert "ax.set_ylabel(\'Number of Records\')" in current_vis_code, "All column not overriden by intent" + assert "ax.set_ylabel('Number of Records')" in current_vis_code, "All column not overriden by intent" lux.config.plotting_backend = "altair" From 82037ffd0df500b0b47e9ac12cd137f558c081f9 Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Mon, 12 Apr 2021 22:15:38 -0700 Subject: [PATCH 34/36] edit --- lux/core/frame.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lux/core/frame.py b/lux/core/frame.py index 6527f311..10c4ce65 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -735,7 +735,6 @@ def render_widget(self, renderer: str = "altair", input_current_vis=""): import luxwidget widgetJSON = self.to_JSON(self._rec_info, input_current_vis=input_current_vis) - return luxwidget.LuxWidget( currentVis=widgetJSON["current_vis"], recommendations=widgetJSON["recommendation"], From 7a44890b9b1a4772bc1c1189b7badee16d93f3c3 Mon Sep 17 00:00:00 2001 From: Doris Lee Date: Sat, 17 Apr 2021 16:19:05 -0700 Subject: [PATCH 35/36] rewrote show all column vis logic and frontend integration to avoid traitlet error --- lux/action/enhance.py | 2 +- lux/action/filter.py | 2 +- lux/core/frame.py | 13 +++++++++---- lux/vis/Vis.py | 1 + lux/vislib/matplotlib/ScatterChart.py | 2 +- tests/test_nan.py | 11 ++++++----- tests/test_vis.py | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) 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 043cf7a0..0c56fb77 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -90,7 +90,6 @@ def __init__(self, *args, **kw): self.pre_aggregated = None self._type_override = {} warnings.formatwarning = lux.warning_format - self.all_column = False @property def _constructor(self): @@ -346,9 +345,11 @@ def _append_rec(self, rec_infolist, recommendations: Dict): rec_infolist.append(recommendations) def show_all_column_vis(self): - quantitative_columns = [i for i in self.dtypes if i != "O" and i != "str"] - if (len(quantitative_columns) == 2 or len(quantitative_columns) == 3) and self._intent == []: - self.current_vis = VisList([i for i in self.columns], 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 @@ -705,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 06e043ac..2dfc7527 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -578,6 +578,6 @@ def test_intent_override_all_column(): df = df[["Year", "Displacement"]] df.intent = ["Year"] df._ipython_display_() - current_vis_code = df.current_vis[0].to_matplotlib_code() + current_vis_code = df.current_vis[0].to_matplotlib() assert "ax.set_ylabel('Number of Records')" in current_vis_code, "All column not overriden by intent" lux.config.plotting_backend = "altair" From 1b7cf75b32734945f1def3c77abc8116b4bbd187 Mon Sep 17 00:00:00 2001 From: Doris Lee Date: Sat, 17 Apr 2021 16:34:34 -0700 Subject: [PATCH 36/36] minor fix --- tests/test_vis.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/test_vis.py b/tests/test_vis.py index 2dfc7527..8f49d292 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -562,22 +562,24 @@ def test_all_column_current_vis(): def test_all_column_current_vis_filter(): - lux.config.plotting_backend = "matplotlib" - df = pytest.car_df - df = df[["Year", "Displacement"]] - df._ipython_display_() - assert df.current_vis != None - - df = df[["Year", "Displacement", "Origin"]] - df._ipython_display_() + 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(): - lux.config.plotting_backend = "matplotlib" df = pytest.car_df df = df[["Year", "Displacement"]] df.intent = ["Year"] df._ipython_display_() - current_vis_code = df.current_vis[0].to_matplotlib() - assert "ax.set_ylabel('Number of Records')" in current_vis_code, "All column not overriden by intent" - lux.config.plotting_backend = "altair" + 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"