Skip to content

Commit 48b5685

Browse files
committed
Increase coverage
1 parent 5811f9e commit 48b5685

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

mplaltair/_axis.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,22 @@ def _set_limits(channel, scale):
3535
# Check that a positive minimum is zero if zero is True:
3636
if ('zero' not in scale or scale['zero'] == True) and min(channel['data']) > 0:
3737
lims[_axis_kwargs[channel['axis']].get('min')] = 0 # quantitative sets min to be 0 by default
38-
else:
39-
pass # use default
4038

4139
# Check that a negative maximum is zero if zero is True:
4240
if ('zero' not in scale or scale['zero'] == True) and max(channel['data']) < 0:
4341
lims[_axis_kwargs[channel['axis']].get('max')] = 0
44-
else:
45-
pass # use default
4642

4743
elif channel['dtype'] == 'temporal':
44+
# determine limits
4845
if 'domain' in scale:
49-
try:
50-
domain = _convert_to_mpl_date(scale['domain'])
51-
except NotImplementedError:
52-
raise NotImplementedError
46+
domain = _convert_to_mpl_date(scale['domain'])
5347
lims[_axis_kwargs[channel['axis']].get('min')] = domain[0]
5448
lims[_axis_kwargs[channel['axis']].get('max')] = domain[1]
5549
elif 'type' in scale and scale['type'] != 'time':
5650
lims = _set_scale_type(channel, scale)
57-
else:
58-
pass # use default
51+
5952
else:
60-
raise NotImplementedError
53+
raise NotImplementedError # Ordinal and Nominal go here?
6154

6255
# set the limits
6356
if channel['axis'] == 'x':
@@ -116,6 +109,7 @@ def _set_scale_type(channel, scale):
116109
def _set_tick_locator(channel, axis):
117110
"""Set the tick locator if it needs to vary from the default"""
118111
# Works for quantitative and temporal
112+
# The auto locator has similar (if not the same) defaults as Altair
119113
current_axis = {'x': channel['ax'].xaxis, 'y': channel['ax'].yaxis}
120114
if 'values' in axis:
121115
if channel['dtype'] == 'temporal':
@@ -128,8 +122,6 @@ def _set_tick_locator(channel, axis):
128122
current_axis[channel['axis']].set_major_locator(
129123
ticker.MaxNLocator(steps=[2, 5, 10], nbins=axis.get('tickCount')+1, min_n_ticks=axis.get('tickCount'))
130124
)
131-
else:
132-
pass # Use the auto locator (it has similar, if not the same settings as Altair)
133125

134126

135127
def _set_tick_formatter(channel, axis):
@@ -150,7 +142,7 @@ def _set_tick_formatter(channel, axis):
150142
except ValueError:
151143
raise ValueError("Matplotlib only supports `strftime` formatting for dates."
152144
"Currently, %L, %Q, and %s are allowed in Altair, but not allowed in Matplotlib."
153-
"Please use a :func:`strftime` compliant format string.")
145+
"Please use a `strftime` compliant format string.")
154146

155147

156148
# TODO: move rotation to another function?
@@ -171,11 +163,8 @@ def _set_tick_formatter(channel, axis):
171163
raise ValueError("Matplotlib only supports format strings as used by `str.format()`."
172164
"Some format strings that work in Altair may not work in Matplotlib."
173165
"Please use a different format string.")
174-
else:
175-
# Use the default formatter for quantitative (it has similar, if not the same settings as Altair)
176-
pass
177166
else:
178-
pass
167+
raise NotImplementedError # Nominal and Ordinal go here
179168

180169

181170
def convert_axis(ax, chart):

mplaltair/tests/test_axis.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def test_axis(df, x, y):
6464
return fig
6565

6666

67+
@pytest.mark.xfail(raises=NotImplementedError)
68+
def test_axis_set_tick_formatter_fail():
69+
"""TODO: Remove this test after merge with ordinal/nominal axis conversion.
70+
This test is just for temporary coverage purposes."""
71+
from .._axis import _set_tick_formatter
72+
_, ax = plt.subplots()
73+
_set_tick_formatter({'ax': ax, 'dtype': 'ordinal'}, {})
74+
75+
6776
@pytest.mark.mpl_image_compare(baseline_dir='baseline_images/test_axis')
6877
@pytest.mark.parametrize('x,y,zero', [('a', 'c', False), ('neg', 'alpha', False),
6978
('a', 'c', True), ('neg', 'alpha', True)])
@@ -195,12 +204,12 @@ def test_axis_scale_type_y_quantitative(column, type, base, exponent):
195204
return fig
196205

197206

198-
# @pytest.mark.mpl_image_compare(baseline_dir='baseline_images/test_axis')
199207
@pytest.mark.xfail(raises=NotImplementedError)
200-
@pytest.mark.parametrize('type', ['pow', 'sqrt', 'utc', 'sequential', 'ordinal'])
201-
def test_axis_scale_NotImplemented_quantitative(type):
202-
chart = alt.Chart(df_quant).mark_point().encode(
203-
alt.X('a', scale=alt.Scale(type=type)),
208+
@pytest.mark.parametrize('df, x, type', [(df_quant, 'a', 'pow'), (df_quant, 'a', 'sqrt'), (df_temp, 'months', 'utc'),
209+
(df_quant, 'a', 'sequential'), (df_quant, 'a', 'ordinal')])
210+
def test_axis_scale_NotImplemented_quantitative(df, x, type):
211+
chart = alt.Chart(df).mark_point().encode(
212+
alt.X(x, scale=alt.Scale(type=type)),
204213
alt.Y('a')
205214
)
206215
mapping = convert(chart)

mplaltair/tests/test_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def test_convert_to_mpl_altair_datetime():
110110
dates = [alt.DateTime(year=2015, date=7).to_dict(), alt.DateTime(year=2015, month="March", date=20).to_dict()]
111111
assert list(_data._convert_to_mpl_date(dates)) == list(mdates.datestr2num(['2015-01-07', '2015-03-20']))
112112

113+
def test_convert_to_mpl_empty():
114+
assert _data._convert_to_mpl_date([]) == []
113115

114116
@pytest.mark.parametrize('date,expected', [
115117
(df_nonstandard['c'].values[0], mdates.datestr2num(df_nonstandard['c'].values[0])),

0 commit comments

Comments
 (0)