Skip to content

Commit 922eac3

Browse files
authored
ci: Temporal examples in vegafusion (#3702)
1 parent 3bda0ac commit 922eac3

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ exclude = [
205205
"__pycache__",
206206
"tests/examples_arguments_syntax",
207207
"tests/examples_methods_syntax",
208-
"tests/test_transformed_data.py",
209208
]
210209

211210
[tool.ruff.lint]

tests/test_transformed_data.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
import pkgutil
22
import sys
3+
from importlib.metadata import version
4+
from importlib.util import find_spec
35

6+
import narwhals.stable.v1 as nw
47
import pytest
5-
from vega_datasets import data
8+
from packaging.version import Version
69

710
import altair as alt
811
from altair.utils.execeval import eval_block
9-
from tests import examples_methods_syntax, slow, ignore_DataFrameGroupBy
10-
import narwhals.stable.v1 as nw
11-
12-
try:
13-
import vegafusion as vf
14-
except ImportError:
15-
vf = None
12+
from tests import (
13+
examples_methods_syntax,
14+
ignore_DataFrameGroupBy,
15+
skip_requires_vegafusion,
16+
slow,
17+
)
18+
from vega_datasets import data
1619

1720
XDIST_ENABLED: bool = "xdist" in sys.modules
1821
"""Use as an `xfail` condition, if running in parallel may cause the test to fail."""
1922

20-
@ignore_DataFrameGroupBy
21-
@pytest.mark.skipif(vf is None, reason="vegafusion not installed")
23+
xfail_vegafusion_2: pytest.MarkDecorator = pytest.mark.xfail(
24+
bool(find_spec("vegafusion"))
25+
and Version(version("vegafusion")) >= Version("2.0.0a0"),
26+
raises=ValueError,
27+
reason="https://github.com/vega/altair/issues/3701",
28+
)
29+
30+
2231
# fmt: off
23-
@pytest.mark.parametrize("filename,rows,cols", [
32+
@ignore_DataFrameGroupBy
33+
@skip_requires_vegafusion
34+
@pytest.mark.parametrize(("filename", "rows", "cols"), [
2435
("annual_weather_heatmap.py", 366, ["monthdate_date_end", "max_temp_max"]),
2536
("anscombe_plot.py", 44, ["Series", "X", "Y"]),
2637
("bar_chart_sorted.py", 6, ["site", "sum_yield"]),
@@ -49,7 +60,7 @@
4960
pytest.param("line_percent.py", 30, ["sex", "perc"], marks=slow),
5061
("line_with_log_scale.py", 15, ["year", "sum_people"]),
5162
("multifeature_scatter_plot.py", 150, ["petalWidth", "species"]),
52-
("natural_disasters.py", 686, ["Deaths", "Year"]),
63+
pytest.param("natural_disasters.py", 686, ["Deaths", "Year"], marks=xfail_vegafusion_2),
5364
("normalized_stacked_area_chart.py", 51, ["source", "net_generation_start"]),
5465
("normalized_stacked_bar_chart.py", 60, ["site", "sum_yield_start"]),
5566
("parallel_coordinates.py", 600, ["key", "value"]),
@@ -69,9 +80,9 @@
6980
("wilkinson-dot-plot.py", 21, ["data", "id"]),
7081
("window_rank.py", 12, ["team", "diff"]),
7182
])
72-
# fmt: on
7383
@pytest.mark.parametrize("to_reconstruct", [True, False])
7484
def test_primitive_chart_examples(filename, rows, cols, to_reconstruct):
85+
# fmt: on
7586
source = pkgutil.get_data(examples_methods_syntax.__name__, filename)
7687
chart = eval_block(source, strict=True)
7788
if to_reconstruct:
@@ -83,17 +94,17 @@ def test_primitive_chart_examples(filename, rows, cols, to_reconstruct):
8394
assert df is not None
8495
nw_df = nw.from_native(df, eager_only=True, strict=True)
8596

86-
assert len(nw_df) == rows
97+
assert len(nw_df) == rows
8798
assert set(cols).issubset(set(nw_df.columns))
8899

89100

90-
@pytest.mark.skipif(vf is None, reason="vegafusion not installed")
91101
# fmt: off
92-
@pytest.mark.parametrize("filename,all_rows,all_cols", [
102+
@skip_requires_vegafusion
103+
@pytest.mark.parametrize(("filename", "all_rows", "all_cols"), [
93104
("errorbars_with_std.py", [10, 10], [["upper_yield"], ["extent_yield"]]),
94105
("candlestick_chart.py", [44, 44], [["low"], ["close"]]),
95106
("co2_concentration.py", [713, 7, 7], [["first_date"], ["scaled_date"], ["end"]]),
96-
("falkensee.py", [2, 38, 38], [["event"], ["population"], ["population"]]),
107+
pytest.param("falkensee.py", [2, 38, 38], [["event"], ["population"], ["population"]], marks=xfail_vegafusion_2),
97108
("heat_lane.py", [10, 10], [["bin_count_start"], ["y2"]]),
98109
("histogram_responsive.py", [20, 20], [["__count"], ["__count"]]),
99110
("histogram_with_a_global_mean_overlay.py", [9, 1], [["__count"], ["mean_IMDB_Rating"]]),
@@ -127,33 +138,33 @@ def test_primitive_chart_examples(filename, rows, cols, to_reconstruct):
127138
("us_employment.py", [120, 1, 2], [["month"], ["president"], ["president"]]),
128139
("us_population_pyramid_over_time.py", [19, 38, 19], [["gender"], ["year"], ["gender"]]),
129140
])
130-
# fmt: on
131141
@pytest.mark.parametrize("to_reconstruct", [True, False])
132142
def test_compound_chart_examples(filename, all_rows, all_cols, to_reconstruct):
143+
# fmt: on
133144
source = pkgutil.get_data(examples_methods_syntax.__name__, filename)
134145
chart = eval_block(source, strict=True)
135146
if to_reconstruct:
136147
# When reconstructing a Chart, Altair uses different classes
137148
# then what might have been originally used. See
138149
# https://github.com/hex-inc/vegafusion/issues/354 for more info.
139150
chart = alt.Chart.from_dict(chart.to_dict())
140-
151+
141152
assert isinstance(chart, (alt.LayerChart, alt.ConcatChart, alt.HConcatChart, alt.VConcatChart))
142153
dfs = chart.transformed_data()
143154

144155
if not to_reconstruct:
145156
# Only run assert statements if the chart is not reconstructed. Reason
146157
# is that for some charts, the original chart contained duplicated datasets
147158
# which disappear when reconstructing the chart.
148-
159+
149160
nw_dfs = (nw.from_native(d, eager_only=True, strict=True) for d in dfs)
150161
assert len(dfs) == len(all_rows)
151162
for df, rows, cols in zip(nw_dfs, all_rows, all_cols):
152163
assert len(df) == rows
153164
assert set(cols).issubset(set(df.columns))
154165

155166

156-
@pytest.mark.skipif(vf is None, reason="vegafusion not installed")
167+
@skip_requires_vegafusion
157168
@pytest.mark.parametrize("to_reconstruct", [True, False])
158169
def test_transformed_data_exclude(to_reconstruct):
159170
source = data.wheat()
@@ -179,5 +190,5 @@ def test_transformed_data_exclude(to_reconstruct):
179190
assert len(_datasets) == 2
180191
assert len(_datasets[0]) == 52
181192
assert "wheat_start" in _datasets[0]
182-
assert len(_datasets[1]) == 1
183-
assert "mean_wheat" in _datasets[1]
193+
assert len(_datasets[1]) == 1
194+
assert "mean_wheat" in _datasets[1]

0 commit comments

Comments
 (0)