Skip to content

Commit 1c5dbca

Browse files
committed
Merge branch 'encodings' of git://github.com/palnabarun/mpl-altair into encodings
2 parents 02d5149 + 15039e3 commit 1c5dbca

File tree

9 files changed

+34
-17
lines changed

9 files changed

+34
-17
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ cache:
66
- $HOME/.cache/pip
77
- $HOME/.cache/matplotlib
88

9+
env:
10+
global:
11+
- MPLBACKEND=agg
12+
913
matrix:
1014
fast_finish: true
1115
include:
@@ -23,7 +27,7 @@ install:
2327
- python -m pip install -ve .
2428

2529
script:
26-
- coverage run run_tests.py
30+
- pytest --cov=mplaltair --mpl
2731
- coverage report -m
2832
- set -e
2933
- codecov

mplaltair/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def convert(chart):
1414
1515
Returns
1616
-------
17-
mapping: dict
18-
Mapping from parts of the encoding to the Matplotlib artists.
19-
This is for later customization
17+
mapping : dict
18+
Mapping from parts of the encoding to the Matplotlib artists. This is
19+
for later customization.
20+
2021
2122
"""
2223
return _convert(chart)

mplaltair/_convert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ def _allowed_ranged_marks(enc_channel, mark):
66
"""
77
return mark in ['area', 'bar', 'rect', 'rule'] if enc_channel in ['x2', 'y2'] else True
88

9-
109
def _process_x(dtype, data):
1110
"""Returns the MPL encoding equivalent for Altair x channel
1211
"""

mplaltair/_data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from ._exceptions import ValidationError
2+
13
def _locate_channel_dtype(chart, channel):
24
"""Locates dtype used for each channel
35
Parameters
@@ -36,6 +38,11 @@ def _locate_channel_data(chart, channel):
3638
-------
3739
A numpy ndarray containing the data used for the channel
3840
41+
Raises
42+
------
43+
ValidationError
44+
Raised when the specification does not contain any data attribute
45+
3946
"""
4047

4148
channel_val = chart.to_dict()['encoding'][channel]

mplaltair/_exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ValidationError(Exception):
2+
pass

mplaltair/tests/test_basic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import matplotlib.pyplot as plt
2+
13
def test_import():
24
import mplaltair
35
del mplaltair
6+
7+
def test_mpl_figure():
8+
fig = plt.figure()
9+
del fig
10+

mplaltair/tests/test_convert.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def test_convert_color_fail():
104104
with pytest.raises(KeyError):
105105
convert(chart_spec)
106106

107-
@pytest.mark.parametrize('channel', ['quant', 'ord'])
108-
def test_convert_fill(channel):
109-
chart_spec = alt.Chart(df).encode(fill=channel).mark_point()
107+
@pytest.mark.parametrize('channel,type', [('quant', 'Q'), ('ord', 'O')])
108+
def test_convert_fill(channel, type):
109+
chart_spec = alt.Chart(df).encode(fill='{}:{}'.format(channel, type)).mark_point()
110110
mapping = convert(chart_spec)
111111
assert list(mapping['c']) == list(df[channel].values)
112112

@@ -121,6 +121,7 @@ def test_convert_fill_success_temporal(column):
121121
mapping = convert(chart)
122122
assert list(mapping['c']) == list(mdates.date2num(df[column].values))
123123

124+
124125
def test_convert_fill_fail():
125126
chart_spec = alt.Chart(df).encode(fill='b:N').mark_point()
126127
with pytest.raises(KeyError):
@@ -156,9 +157,9 @@ def test_convert_opacity_fail_temporal(column):
156157
chart = alt.Chart(df).mark_point().encode(alt.Opacity(column))
157158
convert(chart)
158159

159-
@pytest.mark.parametrize('channel,dtype', [('quant','quantitative'), ('ord', 'ordinal')])
160-
def test_convert_size_success(channel, dtype):
161-
chart_spec = alt.Chart(df).encode(size=alt.Size(field=channel, type=dtype)).mark_point()
160+
@pytest.mark.parametrize('channel,type', [('quant', 'Q'), ('ord', 'O')])
161+
def test_convert_size_success(channel, type):
162+
chart_spec = alt.Chart(df).encode(size='{}:{}'.format(channel, type)).mark_point()
162163
mapping = convert(chart_spec)
163164
assert list(mapping['s']) == list(df[channel].values)
164165

run_tests.py

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

test_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
vega-datasets>=0.5.0
2+
pytest-mpl>=0.9
3+
pytest-cov>=2.5.1

0 commit comments

Comments
 (0)