Skip to content

Commit 9a72a85

Browse files
committed
Add encoding checks
1 parent 43da507 commit 9a72a85

File tree

4 files changed

+20
-61
lines changed

4 files changed

+20
-61
lines changed

mplaltair/_convert.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ def convert(chart):
110110
"""
111111
mapping = {}
112112

113+
if not chart.to_dict().get('encoding'):
114+
raise ValueError("Encoding not provided with the chart specification")
115+
116+
for enc_channel, enc_spec in chart.to_dict()['encoding'].items():
117+
if not _allowed_ranged_marks(enc_channel, chart.to_dict()['mark']):
118+
raise ValueError("Ranged encoding channels like x2, y2 not allowed for Mark: {}".format(chart['mark']))
119+
113120
for channel in chart.to_dict()['encoding']:
114121
data = _locate_channel_data(chart, channel)
115122
dtype = _locate_channel_dtype(chart, channel)

mplaltair/_utils.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

mplaltair/tests/test_convert.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
"s": [50, 100, 200.0], "alpha": [.1, .5, .8], "shape": [1, 2, 3], "fill": [1, 2, 3]
2222
})
2323

24+
25+
def test_encoding_not_provided():
26+
chart_spec = alt.Chart(df).mark_point()
27+
with pytest.raises(ValueError):
28+
convert(chart_spec)
29+
30+
def test_invalid_encodings():
31+
chart_spec = alt.Chart(df).encode(x2='quant').mark_point()
32+
with pytest.raises(ValueError):
33+
convert(chart_spec)
34+
2435
@pytest.mark.parametrize('channel', ['quant', 'ord', 'nom'])
2536
def test_convert_x_success(channel):
2637
chart_spec = alt.Chart(df).encode(x=channel).mark_point()
@@ -55,12 +66,12 @@ def test_convert_y_fail():
5566
with pytest.raises(KeyError):
5667
convert(chart_spec)
5768

58-
@pytest.mark.xfail(raises=NotImplementedError, reason="It doesn't make sense to have x2 and y2 on scatter plots")
69+
@pytest.mark.xfail(raises=ValueError, reason="It doesn't make sense to have x2 and y2 on scatter plots")
5970
def test_quantitative_x2_y2():
6071
chart = alt.Chart(df_quant).mark_point().encode(alt.X('a'), alt.Y('b'), alt.X2('c'), alt.Y2('alpha'))
6172
convert(chart)
6273

63-
@pytest.mark.xfail(raises=NotImplementedError)
74+
@pytest.mark.xfail(raises=ValueError)
6475
@pytest.mark.parametrize("column", ["years", "months", "days", "hrs", "combination"])
6576
def test_convert_x2_y2_fail_temporal(column):
6677
chart = alt.Chart(df).mark_point().encode(alt.X2(column), alt.Y2(column))

mplaltair/tests/test_utils.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)