Exemplo n.º 1
0
 def test_update_list_make_copies_false(self):
     trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2])
     trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1])
     data = Data([trace1, trace2])
     update = dict(x=[2, 3, 4], y=[1, 2, 3], line=Line())
     data.update(update, make_copies=False)
     assert data[0]["line"] is data[1]["line"]
Exemplo n.º 2
0
def test_append_scatter():
    expected = Figure(
        data=Data([Scatter(x=[1, 2, 3], y=[2, 3, 4], xaxis="x5", yaxis="y5")]),
        layout=Layout(
            xaxis1=XAxis(domain=[0.0, 0.2888888888888889], anchor="y1"),
            xaxis2=XAxis(domain=[0.35555555555555557, 0.6444444444444445],
                         anchor="y2"),
            xaxis3=XAxis(domain=[0.7111111111111111, 1.0], anchor="y3"),
            xaxis4=XAxis(domain=[0.0, 0.2888888888888889], anchor="y4"),
            xaxis5=XAxis(domain=[0.35555555555555557, 0.6444444444444445],
                         anchor="y5"),
            xaxis6=XAxis(domain=[0.7111111111111111, 1.0], anchor="y6"),
            yaxis1=YAxis(domain=[0.575, 1.0], anchor="x1"),
            yaxis2=YAxis(domain=[0.575, 1.0], anchor="x2"),
            yaxis3=YAxis(domain=[0.575, 1.0], anchor="x3"),
            yaxis4=YAxis(domain=[0.0, 0.425], anchor="x4"),
            yaxis5=YAxis(domain=[0.0, 0.425], anchor="x5"),
            yaxis6=YAxis(domain=[0.0, 0.425], anchor="x6"),
        ),
    )

    trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
    fig = tls.make_subplots(rows=2, cols=3)
    fig.append_trace(trace, 2, 2)

    d1, d2 = strip_dict_params(fig["data"][0], expected["data"][0])
    assert d1 == d2

    d1, d2 = strip_dict_params(fig["layout"], expected["layout"])
    assert d1 == d2
Exemplo n.º 3
0
    def test_figure_json_encoding(self):
        df = pd.DataFrame(columns=["col 1"], data=[1, 2, 3])
        s1 = Scatter3d(x=numeric_list, y=np_list, z=mixed_list)
        s2 = Scatter(x=df["col 1"])
        data = Data([s1, s2])
        figure = Figure(data=data)

        js1 = _json.dumps(s1, cls=utils.PlotlyJSONEncoder, sort_keys=True)
        js2 = _json.dumps(s2, cls=utils.PlotlyJSONEncoder, sort_keys=True)

        assert (
            js1 == '{"type": "scatter3d", "x": [1, 2, 3], '
            '"y": [1, 2, 3, null, null, null, "2014-01-05T00:00:00"], '
            '"z": [1, "A", "2014-01-05T00:00:00", '
            '"2014-01-05T01:01:01", "2014-01-05T01:01:01.000001"]}'
        )
        assert js2 == '{"type": "scatter", "x": [1, 2, 3]}'

        # Test JSON encoding works
        _json.dumps(data, cls=utils.PlotlyJSONEncoder, sort_keys=True)
        _json.dumps(figure, cls=utils.PlotlyJSONEncoder, sort_keys=True)

        # Test data wasn't mutated
        np_array = np.array([1, 2, 3, np.NaN, np.NAN, np.Inf, dt(2014, 1, 5)])
        for k in range(len(np_array)):
            if k in [3, 4]:
                # check NaN
                assert np.isnan(np_list[k]) and np.isnan(np_array[k])
            else:
                # non-NaN
                assert np_list[k] == np_array[k]

        assert set(data[0]["z"]) == set(
            [
                1,
                "A",
                dt(2014, 1, 5),
                dt(2014, 1, 5, 1, 1, 1),
                dt(2014, 1, 5, 1, 1, 1, 1),
            ]
        )
Exemplo n.º 4
0
def test_append_scatter3d():
    expected = Figure(
        data=Data([
            Scatter3d(x=[1, 2, 3], y=[2, 3, 4], z=[1, 2, 3], scene="scene1"),
            Scatter3d(x=[1, 2, 3], y=[2, 3, 4], z=[1, 2, 3], scene="scene2"),
        ]),
        layout=Layout(
            scene1=Scene(domain={
                "y": [0.575, 1.0],
                "x": [0.0, 1.0]
            }),
            scene2=Scene(domain={
                "y": [0.0, 0.425],
                "x": [0.0, 1.0]
            }),
        ),
    )

    fig = tls.make_subplots(rows=2,
                            cols=1,
                            specs=[[{
                                "is_3d": True
                            }], [{
                                "is_3d": True
                            }]])
    trace = Scatter3d(x=[1, 2, 3], y=[2, 3, 4], z=[1, 2, 3])
    fig.append_trace(trace, 1, 1)
    fig.append_trace(trace, 2, 1)

    d1, d2 = strip_dict_params(fig["data"][0], expected["data"][0])
    assert d1 == d2

    d1, d2 = strip_dict_params(fig["data"][1], expected["data"][1])
    assert d1 == d2

    d1, d2 = strip_dict_params(fig["layout"], expected["layout"])
    assert d1 == d2
Exemplo n.º 5
0
def test_dict_instantiation_graph_obj_error_2():
    assert Data([Annotations()]) == [[]]
Exemplo n.º 6
0
def test_dict_instantiation_graph_obj_error_0():
    assert Annotations([Data()]) == [[]]
Exemplo n.º 7
0
def test_dict_instantiation_key_error_2():
    assert Data([{"marker": "not-a-dict"}]) == [{"marker": "not-a-dict"}]
Exemplo n.º 8
0
def test_dict_instantiation_type_error():
    assert Data([{"type": "invalid_type"}]) == [{"type": "invalid_type"}]
Exemplo n.º 9
0
def test_dict_instantiation_key_error():
    assert Data([{"not-a-key": "anything"}]) == [{"not-a-key": "anything"}]
Exemplo n.º 10
0
def test_dict_instantiation():
    Data([{"type": "scatter"}])
Exemplo n.º 11
0
def test_default_scatter():
    assert Data([{}]) == list([{}])
Exemplo n.º 12
0
def test_weird_instantiation():  # Python allows this...
    assert Data({}) == []
Exemplo n.º 13
0
def test_trivial():
    assert Data() == list()