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 = ChartMetadata( alt.Chart(df_count).mark_point().encode(alt.X('a'), alt.Y('count()')))
def test_invalid_temporal(): # TODO: move to parse_chart tests??? chart = alt.Chart(df).mark_point().encode(alt.X('quant:T')) ChartMetadata(chart)
def test_invalid_encodings(): chart_spec = alt.Chart(df).encode(x2='quant').mark_point() chart = ChartMetadata(chart_spec) with pytest.raises(ValueError): _convert(chart)
def test_encoding_not_provided(): # TODO: move to the parse_chart tests chart_spec = alt.Chart(df).mark_point() with pytest.raises(ValueError): chart = ChartMetadata(chart_spec)
def test_timeUnit(): chart = ChartMetadata( alt.Chart(df).mark_point().encode(alt.X('date(combination)')))
def test_convert_y_success_temporal(column): chart = ChartMetadata(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_x2_y2_fail_temporal(column): chart = ChartMetadata( alt.Chart(df).mark_point().encode(alt.X2(column), alt.Y2(column))) _convert(chart)
def test_convert_size_success(channel, type): chart_spec = ChartMetadata( 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_size_success_nominal(): with pytest.raises(NotImplementedError): chart_spec = ChartMetadata( alt.Chart(df).encode(size='nom').mark_point()) _convert(chart_spec)
def test_quantitative_opacity_array(): chart = ChartMetadata( alt.Chart(df_quant).mark_point().encode(alt.Opacity('alpha'))) _convert(chart)
def test_convert_opacity_fail_temporal(column): chart = ChartMetadata( alt.Chart(df).mark_point().encode(alt.Opacity(column))) _convert(chart)
def test_quantitative_opacity_value(): chart = ChartMetadata( alt.Chart(df_quant).mark_point().encode(opacity=alt.value(.5)))
def test_quantitative_shape(): chart = ChartMetadata( alt.Chart(df_quant).mark_point().encode(alt.Shape('shape'))) mapping = _convert(chart)
def test_convert_color_success(channel, dtype): chart_spec = ChartMetadata( alt.Chart(df).encode( color=alt.Color(field=channel, type=dtype)).mark_point()) mapping = _convert(chart_spec) assert list(mapping['c']) == list(df[channel].values)
def test_convert_x_success(channel): chart_spec = alt.Chart(df).encode(x=channel).mark_point() chart = ChartMetadata(chart_spec) mapping = _convert(chart) assert list(mapping['x']) == list(df[channel].values)
def test_quantitative_stroke(): chart = ChartMetadata( alt.Chart(df_quant).mark_point().encode(alt.Stroke('fill'))) _convert(chart)
def test_convert_y_success(channel): chart_spec = ChartMetadata(alt.Chart(df).encode(y=channel).mark_point()) mapping = _convert(chart_spec) assert list(mapping['y']) == list(df[channel].values)
def test_convert_stroke_fail_temporal(column): chart = ChartMetadata( alt.Chart(df).mark_point().encode(alt.Stroke(column))) _convert(chart)
def test_convert_y_fail(): with pytest.raises(KeyError): chart_spec = ChartMetadata(alt.Chart(df).encode(y='b:N').mark_point())
def test_quantitative_x2_y2(): chart = ChartMetadata( alt.Chart(df_quant).mark_point().encode(alt.X('a'), alt.Y('b'), alt.X2('c'), alt.Y2('alpha'))) _convert(chart)