def test_line(self): chart = alt.Chart(df_line).mark_line().encode( alt.X('a'), alt.Y('b'), ) fig, _ = convert(chart) return fig
def test_axis_scale_NotImplemented_quantitative(df, x, type): chart = alt.Chart(df).mark_point().encode( alt.X(x, scale=alt.Scale(type=type)), alt.Y('a')) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart)
def test_scatter_temporal(channel): chart = alt.Chart(df).mark_point().encode(alt.X("years"), channel) mapping = convert(chart) mapping['y'] = df['quantitative'].values fig, ax = plt.subplots() ax.scatter(**mapping) return fig
def test_axis_scale_type_y_quantitative(column, type, base, exponent): chart = alt.Chart(df_quant).mark_point().encode( alt.X('a'), alt.Y(column, scale=alt.Scale(type=type, base=base, exponent=exponent))) fig, ax = convert(chart) plt.show() return fig
def test_axis(df, x, y): chart = alt.Chart(df).mark_point().encode(alt.X(x), alt.Y(y)) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_formatter_fail(): chart = alt.Chart(df_quant).mark_point().encode( alt.X('c', axis=alt.Axis(format='-$.2g')), alt.Y('b', axis=alt.Axis(format='+.3r'))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart)
def test_axis_formatter_temporal(): """Note: this test is separate from the other test_axis_formatter test because the parametrization created issues with the filename for the image comparison test.""" chart = alt.Chart(df_temp).mark_point().encode( alt.X('months:T', axis=alt.Axis(format='%b %Y')), alt.Y('hrs:T', axis=alt.Axis(format='%H:%M:%S'))) fig, ax = convert(chart) return fig
def test_quantitative_x_count_y(): df_count = pd.DataFrame({ "a": [1, 1, 2, 3, 5], "b": [1.4, 1.4, 2.9, 3.18, 5.3] }) chart = alt.Chart(df_count).mark_point().encode(alt.X('a'), alt.Y('count()')) mapping = convert(chart)
def test_axis_scale_basic(df, column, scale_type): chart = alt.Chart(df).mark_point().encode( alt.X(column, scale=alt.Scale(type=scale_type)), alt.Y('a')) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_unaggregated_quantitative(): chart = alt.Chart(df_quant).mark_point().encode( alt.X('a', scale=alt.Scale(domain="unaggregated")), alt.Y('c', scale=alt.Scale(domain="unaggregated"))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) plt.close() convert_axis(ax, chart)
def test_axis_more_than_x_and_y(): chart = alt.Chart(df_quant).mark_point().encode(alt.X('a'), alt.Y('b'), color=alt.Color('c')) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_formatter(df, x, y, format_x, format_y): chart = alt.Chart(df).mark_point().encode( alt.X(x, axis=alt.Axis(format=format_x)), alt.Y(y, axis=alt.Axis(format=format_y))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_scale_type_x_quantitative(column, type, base, exponent): chart = alt.Chart(df_quant).mark_point().encode( alt.X(column, scale=alt.Scale(type=type, base=base, exponent=exponent)), alt.Y('a')) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_tickCount(df, x, tickCount): chart = alt.Chart(df).mark_point().encode( alt.X(x, axis=alt.Axis(tickCount=tickCount)), alt.Y('a', axis=alt.Axis(tickCount=tickCount))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_values(df, y, vals): chart = alt.Chart(df).mark_point().encode( alt.X('a', axis=alt.Axis(values=[-1, 1, 1.5, 2.125, 3])), alt.Y(y, axis=alt.Axis(values=vals))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_domain(df, x, y, x_dom, y_dom): chart = alt.Chart(df).mark_point().encode( alt.X(x, scale=alt.Scale(domain=x_dom)), alt.Y(y, scale=alt.Scale(domain=y_dom))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_axis_zero_quantitative(x, y, zero): chart = alt.Chart(df_quant).mark_point().encode( alt.X(x, scale=alt.Scale(zero=zero)), alt.Y(y, scale=alt.Scale(zero=zero))) mapping = convert(chart) fig, ax = plt.subplots() ax.scatter(**mapping) convert_axis(ax, chart) fig.tight_layout() return fig
def test_convert_y_success_temporal(column): chart = alt.Chart(df).mark_point().encode(alt.Y(column)) mapping = convert(chart) assert list(mapping['y']) == list(mdates.date2num(df[column].values))
def test_convert_y_fail(): chart_spec = alt.Chart(df).encode(y='b:N').mark_point() with pytest.raises(KeyError): convert(chart_spec)
def test_invalid_temporal(): chart = alt.Chart(df).mark_point().encode(alt.X('quant:T')) convert(chart)
def test_convert_y_success(channel): chart_spec = alt.Chart(df).encode(y=channel).mark_point() mapping = convert(chart_spec) assert list(mapping['y']) == list(df[channel].values)
def test_encoding_not_provided(): chart_spec = alt.Chart(df).mark_point() with pytest.raises(ValueError): convert(chart_spec)
def test_invalid_encodings(): chart_spec = alt.Chart(df).encode(x2='quant').mark_point() with pytest.raises(ValueError): convert(chart_spec)
def test_quantitative_scatter(chart): mapping = convert(chart) plt.scatter(**mapping) plt.show()
def test_scatter_temporal(channel): chart = alt.Chart(df).mark_point().encode(alt.X("years"), channel) mapping = convert(chart) mapping['y'] = df['quantitative'].values plt.scatter(**mapping) plt.show()
def test_timeUnit(): chart = alt.Chart(df).mark_point().encode(alt.X('date(combination)')) convert(chart)
def test_convert_size_success(channel, type): chart_spec = alt.Chart(df).encode( size='{}:{}'.format(channel, type)).mark_point() mapping = convert(chart_spec) assert list(mapping['s']) == list(df[channel].values)
def test_convert_stroke_fail_temporal(column): chart = alt.Chart(df).mark_point().encode(alt.Stroke(column)) convert(chart)
def test_quantitative_stroke(): chart = alt.Chart(df_quant).mark_point().encode(alt.Stroke('fill')) convert(chart)
def test_convert_size_success_nominal(): chart_spec = alt.Chart(df).encode(size='nom').mark_point() with pytest.raises(NotImplementedError): convert(chart_spec)