Exemplo n.º 1
0
def test_bar_x_label_ordering():
    def make_row(name, abbrev, value):
        return {
            "name": name,
            "abbrev": abbrev,
            "category": "total",
            "metric": "mae",
            "value": value,
            "index": 0
        }

    data = [
        make_row(n, a, v)
        for n, a, v in [("EA GHI", "EA GHI",
                         5), ("DA GHi01", "DA GHi.",
                              3), ("DA GHi02", "DA GHi.",
                                   4), ("DA GHi03", "DA GHi.",
                                        7), ("CA GHI", "CA GHI", 1)]
    ]
    df = pd.DataFrame(data)

    figure = figures.bar(df, "mae")

    # Ensure x labels are in expected order
    assert (figure.data[0]['x'] == np.array([
        "CA GHI", "DA GHi.", "DA GHi.\ufeff", "DA GHi.\ufeff\ufeff", "EA GHI"
    ],
                                            dtype=object)).all()
    # ensure y values are in the same order as x labels
    assert (figure.data[0]['y'] == np.array([1, 3, 4, 7, 5])).all()
    # assert hover text (original name) matches x label order
    assert (figure.data[0]['text'] == np.array(
        ['CA GHI', "DA GHi01", "DA GHi02", "DA GHi03", "EA GHI"])).all()
Exemplo n.º 2
0
def test_bar_height_tick_adjustment(metric_dataframe, new_name, tickangle,
                                    height):
    metric_dataframe['abbrev'] = new_name
    out = figures.bar(metric_dataframe, 'mae')
    assert isinstance(out, graph_objects.Figure)
    assert out.layout.height == height
    assert out.layout.xaxis.tickangle == tickangle
    assert out.layout.xaxis.automargin
Exemplo n.º 3
0
def test_bar(metric_dataframe):
    out = figures.bar(metric_dataframe, 'mae')
    assert isinstance(out, graph_objects.Figure)
    plot_spec = out.to_dict()
    layout = plot_spec['layout']
    assert 'automargin' not in layout['xaxis']
    assert 'tickangle' not in layout['xaxis']
    assert layout['height'] == figures.PLOT_LAYOUT_DEFAULTS['height']
Exemplo n.º 4
0
def test_bar_empty_df(metric_dataframe):
    df = pd.DataFrame(columns=metric_dataframe.columns)
    out = figures.bar(df, 's')
    assert isinstance(out, graph_objects.Figure)
Exemplo n.º 5
0
def test_bar_no_metric(metric_dataframe):
    out = figures.bar(metric_dataframe, 'rmse')
    assert isinstance(out, graph_objects.Figure)