diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 62159b8c..8dc1b0be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,5 +57,4 @@ jobs: run: | cd packages/widget - ruff . - black . --check + ruff ../.. diff --git a/dev/notebooks/motherduck.ipynb b/dev/notebooks/motherduck.ipynb index 787632d4..68070a9e 100644 --- a/dev/notebooks/motherduck.ipynb +++ b/dev/notebooks/motherduck.ipynb @@ -19,6 +19,7 @@ "source": [ "import duckdb\n", "import yaml\n", + "\n", "from mosaic_widget import MosaicWidget" ] }, @@ -33,7 +34,7 @@ "source": [ "con = duckdb.connect()\n", "\n", - "share = 'md:_share/gaia-import/c551f2da-3258-4387-ac43-f4be601850ac'\n", + "share = \"md:_share/gaia-import/c551f2da-3258-4387-ac43-f4be601850ac\"\n", "con.execute(f\"ATTACH '{share}' AS share\")\n", "\n", "con.execute(\"ATTACH ':memory:' AS local\")\n", @@ -135,14 +136,17 @@ "\n", "c = duckdb.connect(\"md:gaia-import\")\n", "\n", - "c.execute(\"\"\"\n", + "c.execute(\n", + " \"\"\"\n", "CREATE TABLE IF NOT EXISTS gaia_sample_5_percent AS\n", " SELECT l, b, ra, dec, phot_g_mean_mag, parallax, bp_rp\n", " FROM gaia\n", " USING SAMPLE 5 PERCENT (bernoulli)\n", - "\"\"\")\n", + "\"\"\"\n", + ")\n", "\n", - "c.execute(\"\"\"\n", + "c.execute(\n", + " \"\"\"\n", "CREATE TABLE IF NOT EXISTS gaia_sample_5_percent_projected AS\n", "WITH tmp AS (\n", " SELECT\n", @@ -159,7 +163,8 @@ " t * (1.340264 + (-0.081106 * t2) + (t6 * (0.000893 + 0.003796 * t2))) AS v,\n", " * EXCLUDE('t', 't2', 't6')\n", "FROM tmp\n", - "\"\"\")" + "\"\"\"\n", + ")" ] }, { diff --git a/dev/notebooks/specs.ipynb b/dev/notebooks/specs.ipynb index 574de944..03821b36 100644 --- a/dev/notebooks/specs.ipynb +++ b/dev/notebooks/specs.ipynb @@ -9,11 +9,13 @@ }, "outputs": [], "source": [ + "from pprint import pprint\n", + "\n", "import duckdb\n", - "import yaml\n", - "from mosaic_widget import MosaicWidget\n", "import ipywidgets as widgets\n", - "from pprint import pprint" + "import yaml\n", + "\n", + "from mosaic_widget import MosaicWidget" ] }, { @@ -27,6 +29,7 @@ "source": [ "# Optional: enable logging in Mosaic widget\n", "import logging\n", + "\n", "logging.basicConfig(level=logging.INFO)" ] }, @@ -103,29 +106,34 @@ " (\"Symbols\", \"symbols\"),\n", " (\"Table\", \"table\"),\n", " (\"Voronoi\", \"voronoi\"),\n", - " (\"Wind Map\", \"wind-map\")\n", + " (\"Wind Map\", \"wind-map\"),\n", " ],\n", " value=\"weather\",\n", - " description=\"Example:\"\n", + " description=\"Example:\",\n", ")\n", "\n", + "\n", "def on_change(change):\n", " open_spec(change[\"new\"])\n", "\n", + "\n", "def open_spec(spec):\n", " with open(f\"dev/yaml/{spec}.yaml\") as f:\n", " mosaic.spec = yaml.safe_load(f)\n", "\n", + "\n", "dropdown.observe(on_change, \"value\")\n", "\n", "open_spec(\"weather\")\n", "\n", "output = widgets.Output()\n", "\n", + "\n", "@output.capture(clear_output=True)\n", "def handle_change(change):\n", " pprint(change.new)\n", "\n", + "\n", "mosaic.observe(handle_change, names=[\"selections\"])" ] }, @@ -144,9 +152,9 @@ ], "metadata": { "kernelspec": { - "display_name": "mosaic", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "mosaic" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -158,7 +166,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/dev/notebooks/weather.ipynb b/dev/notebooks/weather.ipynb index 5f854dae..1ddb918d 100644 --- a/dev/notebooks/weather.ipynb +++ b/dev/notebooks/weather.ipynb @@ -11,6 +11,7 @@ "source": [ "import pandas as pd\n", "import yaml\n", + "\n", "from mosaic_widget import MosaicWidget" ] }, @@ -25,6 +26,7 @@ "source": [ "# Optional: enable logging in Mosaic widget\n", "import logging\n", + "\n", "logging.basicConfig(level=logging.INFO)" ] }, @@ -37,7 +39,7 @@ }, "outputs": [], "source": [ - "weather = pd.read_csv(\"../../data/seattle-weather.csv\", parse_dates=['date'])\n", + "weather = pd.read_csv(\"../../data/seattle-weather.csv\", parse_dates=[\"date\"])\n", "\n", "# Load weather spec, remove data key to ensure load from Pandas\n", "with open(\"../yaml/weather.yaml\") as f:\n", @@ -54,7 +56,7 @@ }, "outputs": [], "source": [ - "MosaicWidget(spec, data = {\"weather\": weather})" + "MosaicWidget(spec, data={\"weather\": weather})" ] } ], @@ -74,7 +76,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/packages/widget/mosaic_widget/__init__.py b/packages/widget/mosaic_widget/__init__.py index d42e073a..dc86a7ac 100644 --- a/packages/widget/mosaic_widget/__init__.py +++ b/packages/widget/mosaic_widget/__init__.py @@ -1,10 +1,11 @@ -import duckdb -import anywidget -import traitlets -import pyarrow as pa +import logging import pathlib import time -import logging + +import anywidget +import duckdb +import pyarrow as pa +import traitlets logger = logging.getLogger(__name__) logger.addHandler(logging.NullHandler()) @@ -37,10 +38,10 @@ class MosaicWidget(anywidget.AnyWidget): def __init__( self, - spec: dict = {}, - con=duckdb.connect(), + spec: dict = None, + con=None, temp_indexes=True, - data={}, + data=None, *args, **kwargs, ): @@ -50,11 +51,18 @@ def __init__( spec (dict, optional): The initial Mosaic specification. Defaults to {}. con (connection, optional): A DuckDB connection. Defaults to duckdb.connect(). - data (dict, optional): Pandas DataFrames to add to DuckDB. - The keys are used as the names of the tables. Defaults to {}. temp_indexes (bool, optional): Whether data cube indexes should be created as temp tables tables. Defaults to True. + data (dict, optional): Pandas DataFrames to add to DuckDB. + The keys are used as the names of the tables. Defaults to {}. """ + if data is None: + data = {} + if spec is None: + spec = {} + if con is None: + con = duckdb.connect() + super().__init__(*args, **kwargs) self.spec = spec self.con = con diff --git a/packages/widget/pyproject.toml b/packages/widget/pyproject.toml index 435f6b59..16fc0abf 100644 --- a/packages/widget/pyproject.toml +++ b/packages/widget/pyproject.toml @@ -27,7 +27,6 @@ dev = [ "jupyterlab", "pandas", "pyyaml", - "black[jupyter]", "ruff", ] @@ -37,14 +36,32 @@ features = ["dev"] [tool.hatch.envs.default.scripts] style = [ - "ruff {args:.}", - "black --check --diff {args:.}" + "ruff {args:../..}", ] fmt = [ - "black {args:.}", - "ruff --fix {args:.}" + "ruff format {args:../..}", + "ruff --fix {args:../..}" ] [tool.hatch.version] path = "package.json" pattern = "\"version\": \"(?P.+?)\"" + +[tool.ruff] +extend-include = ["*.ipynb"] +# allow long lines, allow end in ;, allow useless expressions +ignore = ["E501", "E703", "B018"] +select = [ + # pycodestyle + "E", + # Pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # flake8-simplify + "SIM", + # isort + "I", +]