From 11f47181bd9f166231ef4fe6b963f31875fa0aa9 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 28 Sep 2024 19:48:16 -0400 Subject: [PATCH] v2: Remove altair functionality from vegafusion package (#510) * Remove altair functionality from vegafusion package * remove altair dep * Install altair when testing --- .github/workflows/build_test.yml | 6 +- pixi.lock | 50 +++--- pixi.toml | 1 + python/vegafusion/setup.cfg | 1 - .../vegafusion/tests/test_context_manager.py | 34 ---- python/vegafusion/tests/test_row_limit.py | 32 ---- python/vegafusion/tests/test_save.py | 59 ------- .../vegafusion/tests/test_transformed_data.py | 10 +- python/vegafusion/vegafusion/__init__.py | 111 ------------- python/vegafusion/vegafusion/evaluation.py | 13 -- python/vegafusion/vegafusion/jupyter.py | 4 - python/vegafusion/vegafusion/renderer.py | 83 ---------- python/vegafusion/vegafusion/save.py | 152 ------------------ python/vegafusion/vegafusion/transformer.py | 60 ------- 14 files changed, 31 insertions(+), 585 deletions(-) delete mode 100644 python/vegafusion/tests/test_context_manager.py delete mode 100644 python/vegafusion/tests/test_row_limit.py delete mode 100644 python/vegafusion/tests/test_save.py delete mode 100644 python/vegafusion/vegafusion/evaluation.py delete mode 100644 python/vegafusion/vegafusion/jupyter.py delete mode 100644 python/vegafusion/vegafusion/renderer.py delete mode 100644 python/vegafusion/vegafusion/save.py diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 458b30c2c..7c5520ead 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -299,7 +299,7 @@ jobs: python -m pip install polars-lts-cpu "duckdb>=1.0" "vl-convert-python>=1.0.1rc1" scikit-image "pandas>=2.2" jupytext voila anywidget ipywidgets chromedriver-binary-auto # Test dependencies - python -m pip install pytest vega-datasets scikit-image jupytext voila ipykernel anywidget ipywidgets selenium flaky tenacity chromedriver-binary-auto + python -m pip install pytest altair vega-datasets scikit-image jupytext voila ipykernel anywidget ipywidgets selenium flaky tenacity chromedriver-binary-auto - name: Test lazy imports working-directory: python/vegafusion/ run: python checks/check_lazy_imports.py @@ -347,7 +347,7 @@ jobs: python -m pip install polars "duckdb>=1.0" vl-convert-python "pandas>=2.2" # Test dependencies - python -m pip install pytest vega-datasets scikit-image + python -m pip install pytest altair vega-datasets scikit-image - name: Test vegafusion working-directory: python/vegafusion/ @@ -392,7 +392,7 @@ jobs: python -m pip install pyarrow==10.0 altair==5.1.2 polars[timezone] "duckdb>=1.0" vl-convert-python # Test dependencies - python -m pip install pytest vega-datasets scikit-image + python -m pip install pytest altair vega-datasets scikit-image - name: Test vegafusion working-directory: python/vegafusion/ run: pytest --ignore=tests/test_altair_mocks.py diff --git a/pixi.lock b/pixi.lock index 63c282373..1a7959574 100644 --- a/pixi.lock +++ b/pixi.lock @@ -816,7 +816,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pkgutil-resolve-name-1.3.10-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.10.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pluggy-1.2.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/osx-arm64/polars-0.18.15-py310had9acf8_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/polars-0.18.15-py310h49106b5_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pooch-1.7.0-pyha770c72_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.17.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/prompt-toolkit-3.0.39-pyha770c72_0.conda @@ -12051,12 +12051,10 @@ packages: depends: - libgcc-ng >=12 - numpy >=1.16.0 - - packaging * + - packaging - python >=3.10,<3.11.0a0 - python_abi 3.10.* *_cp310 - typing_extensions >=4.0.0 - arch: x86_64 - platform: linux license: MIT license_family: MIT size: 16057056 @@ -12064,44 +12062,42 @@ packages: - kind: conda name: polars version: 0.18.15 - build: py310h95fa17d_1 + build: py310h49106b5_1 build_number: 1 - subdir: osx-64 - url: https://conda.anaconda.org/conda-forge/osx-64/polars-0.18.15-py310h95fa17d_1.conda - sha256: 423ebf36060323f5f145b23437dbbdf7c5735d1f5c536adcc463d2434b1812f1 - md5: ca50abd3aa922d6d8d8f1a3ff0dda332 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/polars-0.18.15-py310h49106b5_1.conda + sha256: ebc61b1e954585f492e777cd5d2caa06c2e0e28c0be364ab0c412294b72fe13b + md5: 51481d96d1b4c863662e81d075ad5d79 depends: - numpy >=1.16.0 - - packaging * + - packaging - python >=3.10,<3.11.0a0 + - python >=3.10,<3.11.0a0 *_cpython - python_abi 3.10.* *_cp310 - typing_extensions >=4.0.0 - arch: x86_64 - platform: osx license: MIT license_family: MIT - size: 13970392 - timestamp: 1692690680600 + size: 12963300 + timestamp: 1692690752488 - kind: conda name: polars version: 0.18.15 - build: py310had9acf8_0 - subdir: osx-arm64 - url: https://conda.anaconda.org/conda-forge/osx-arm64/polars-0.18.15-py310had9acf8_0.conda - sha256: 9d50cec48ac801a5ec4b44fb3c00d761ce55d1e1af479cef1d9cff3dd7c66dfa - md5: 9fb570a944037614daba1b125648588d + build: py310h95fa17d_1 + build_number: 1 + subdir: osx-64 + url: https://conda.anaconda.org/conda-forge/osx-64/polars-0.18.15-py310h95fa17d_1.conda + sha256: 423ebf36060323f5f145b23437dbbdf7c5735d1f5c536adcc463d2434b1812f1 + md5: ca50abd3aa922d6d8d8f1a3ff0dda332 depends: - numpy >=1.16.0 - - python >=3.10,<3.11.0a0 *_cpython + - packaging + - python >=3.10,<3.11.0a0 - python_abi 3.10.* *_cp310 - typing_extensions >=4.0.0 - - packaging * - arch: aarch64 - platform: osx license: MIT license_family: MIT - size: 12977174 - timestamp: 1692100866706 + size: 13970392 + timestamp: 1692690680600 - kind: conda name: polars version: 0.18.15 @@ -12113,15 +12109,13 @@ packages: md5: 14eed67eba855b1ddcffb7f89586875e depends: - numpy >=1.16.0 - - packaging * + - packaging - python >=3.10,<3.11.0a0 - python_abi 3.10.* *_cp310 - typing_extensions >=4.0.0 - ucrt >=10.0.20348.0 - vc >=14.2,<15 - vc14_runtime >=14.29.30139 - arch: x86_64 - platform: win license: MIT license_family: MIT size: 14328233 diff --git a/pixi.toml b/pixi.toml index c875a7307..2a369c179 100644 --- a/pixi.toml +++ b/pixi.toml @@ -139,6 +139,7 @@ ipywidgets = "8.1.0.*" rust = "1.80.*" vl-convert-python = "1.6.*" anywidget = ">=0.9.6,<0.10" +polars = "1.8.*" [target.osx-arm64.build-dependencies] # These dependencies are for building node canvas from source on apple silicon diff --git a/python/vegafusion/setup.cfg b/python/vegafusion/setup.cfg index 8da2b7153..4e5572ef1 100644 --- a/python/vegafusion/setup.cfg +++ b/python/vegafusion/setup.cfg @@ -27,7 +27,6 @@ packages = find: python_requires = >=3.7 include_package_data = True install_requires = - altair>=5.2.0 pyarrow>=5 pandas psutil diff --git a/python/vegafusion/tests/test_context_manager.py b/python/vegafusion/tests/test_context_manager.py deleted file mode 100644 index cbc8d4325..000000000 --- a/python/vegafusion/tests/test_context_manager.py +++ /dev/null @@ -1,34 +0,0 @@ -import altair as alt -import vegafusion as vf - - -def test_mime_enabler_context_manager(): - alt.data_transformers.enable("json") - alt.renderers.enable("mimetype") - - assert alt.data_transformers.active == "json" - assert alt.renderers.active == "mimetype" - - with vf.disable(): - assert alt.data_transformers.active == "default" - assert alt.renderers.active == "default" - - assert alt.data_transformers.active == "json" - assert alt.renderers.active == "mimetype" - - ctx = vf.disable() - assert alt.data_transformers.active == "default" - assert alt.renderers.active == "default" - assert repr(ctx) == "vegafusion.disable()" - - with vf.enable(): - assert alt.data_transformers.active == "vegafusion-inline" - assert alt.renderers.active == "vegafusion-mime" - - assert alt.data_transformers.active == "default" - assert alt.renderers.active == "default" - - ctx = vf.enable() - assert alt.data_transformers.active == "vegafusion-inline" - assert alt.renderers.active == "vegafusion-mime" - assert repr(ctx) == "vegafusion.enable(mimetype='html', row_limit=10000, embed_options={})" diff --git a/python/vegafusion/tests/test_row_limit.py b/python/vegafusion/tests/test_row_limit.py deleted file mode 100644 index f9bbbd1a5..000000000 --- a/python/vegafusion/tests/test_row_limit.py +++ /dev/null @@ -1,32 +0,0 @@ -import pytest -import vegafusion as vf -import altair as alt -from altair.utils.execeval import eval_block -from pathlib import Path -here = Path(__file__).parent -altair_mocks_dir = here / "altair_mocks" - - -def test_row_limit(): - mock_path = altair_mocks_dir / "scatter" / "bubble_plot" / "mock.py" - mock_src = mock_path.read_text("utf8") - chart = eval_block(mock_src) - - # Dataset has 406 rows (before filtering out nulls) and this chart is not aggregated. - # Limit of 500 rows should be fine - with vf.enable(row_limit=500): - chart._repr_mimebundle_() - - # Limit of 300 rows should raise RowLimitError - with vf.enable(row_limit=300): - with pytest.raises(vf.RowLimitError): - chart._repr_mimebundle_() - - # Adding an aggregation should allow row limit to be much lower - chart = chart.encode( - alt.X("Horsepower", bin=True), - alt.Y("Miles_per_Gallon", bin=True), - alt.Size("count()") - ) - with vf.enable(row_limit=50): - chart._repr_mimebundle_() diff --git a/python/vegafusion/tests/test_save.py b/python/vegafusion/tests/test_save.py deleted file mode 100644 index 1c639a2d0..000000000 --- a/python/vegafusion/tests/test_save.py +++ /dev/null @@ -1,59 +0,0 @@ -import altair as alt -from vega_datasets import data -import vegafusion as vf -from io import StringIO, BytesIO -import json - - -def make_histogram(): - source = data.movies.url - return alt.Chart(source).mark_bar().encode( - alt.X("IMDB_Rating:Q", bin=True), - y='count()', - ) - - -def test_save_html(): - chart = make_histogram() - f = StringIO() - vf.save_html(chart, f) - html = f.getvalue().strip() - assert html.startswith("") - assert "https://cdn.jsdelivr.net/npm/vega@5" in html - assert "https://cdn.jsdelivr.net/npm/vega-embed@6" in html - - -# We can't test inline HTML until after a new release of Altair Viewer -# def test_save_html_inline(): -# chart = make_histogram() -# f = StringIO() -# vf.save_html(chart, f, inline=True) -# html = f.getvalue().strip() -# assert html.startswith("") -# assert "