Ejemplo n.º 1
0
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()')))
Ejemplo n.º 2
0
def test_invalid_temporal():  # TODO: move to parse_chart tests???
    chart = alt.Chart(df).mark_point().encode(alt.X('quant:T'))
    ChartMetadata(chart)
Ejemplo n.º 3
0
def test_invalid_encodings():
    chart_spec = alt.Chart(df).encode(x2='quant').mark_point()
    chart = ChartMetadata(chart_spec)
    with pytest.raises(ValueError):
        _convert(chart)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def test_timeUnit():
    chart = ChartMetadata(
        alt.Chart(df).mark_point().encode(alt.X('date(combination)')))
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
def test_convert_x2_y2_fail_temporal(column):
    chart = ChartMetadata(
        alt.Chart(df).mark_point().encode(alt.X2(column), alt.Y2(column)))
    _convert(chart)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
def test_convert_size_success_nominal():
    with pytest.raises(NotImplementedError):
        chart_spec = ChartMetadata(
            alt.Chart(df).encode(size='nom').mark_point())
        _convert(chart_spec)
Ejemplo n.º 10
0
def test_quantitative_opacity_array():
    chart = ChartMetadata(
        alt.Chart(df_quant).mark_point().encode(alt.Opacity('alpha')))
    _convert(chart)
Ejemplo n.º 11
0
def test_convert_opacity_fail_temporal(column):
    chart = ChartMetadata(
        alt.Chart(df).mark_point().encode(alt.Opacity(column)))
    _convert(chart)
Ejemplo n.º 12
0
def test_quantitative_opacity_value():
    chart = ChartMetadata(
        alt.Chart(df_quant).mark_point().encode(opacity=alt.value(.5)))
Ejemplo n.º 13
0
def test_quantitative_shape():
    chart = ChartMetadata(
        alt.Chart(df_quant).mark_point().encode(alt.Shape('shape')))
    mapping = _convert(chart)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
def test_quantitative_stroke():
    chart = ChartMetadata(
        alt.Chart(df_quant).mark_point().encode(alt.Stroke('fill')))
    _convert(chart)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
def test_convert_stroke_fail_temporal(column):
    chart = ChartMetadata(
        alt.Chart(df).mark_point().encode(alt.Stroke(column)))
    _convert(chart)
Ejemplo n.º 19
0
def test_convert_y_fail():
    with pytest.raises(KeyError):
        chart_spec = ChartMetadata(alt.Chart(df).encode(y='b:N').mark_point())
Ejemplo n.º 20
0
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)