Debian Codegraph @

bqplot/tests/marks_test.py

raw
1 import bqplot
2 import numpy as np
3 import pytest
4
5
6 def test_scatter(figure):
7 x = np.arange(10, dtype=np.float64)
8 y = (x**2).astype(np.int32)
9 scatter = bqplot.Scatter(x=x, y=y)
10 assert scatter.x.dtype == np.float64
11 assert scatter.y.dtype == np.int32
12
13 assert scatter.x.shape == (10,)
14 assert scatter.y.shape == (10,)
15
16
17 def test_lines(scales):
18 # Create a Line chart with data of multiple shapes should work with binary serialization
19 lines = bqplot.Lines(x=np.array([[0, 1], [0, 1, 2]], dtype=object), y=np.array([[0, 1], [1, 0, -1]], dtype=object), scales=scales)
20
21 lines = bqplot.Lines(x=[[0, 1], [0, 1]], y=[[0, 1], [1, 0]], scales=scales)
22 state = lines.get_state()
23
24 lines2 = bqplot.Lines(scales=scales)
25 lines2.set_state(state)
26 assert lines.x[0][0] == 0
27 assert lines.x[0][1] == 1
28 assert lines.x[1][1] == 1
29
30 def test_lines_ordinal(scale_ordinal, scale_y):
31 scales = {'x': scale_ordinal, 'y': scale_y}
32 lines = bqplot.Lines(x=list('ABC'), y=[1, 2, 3], scales=scales)
33
34
35 def test_bars(scales):
36 # Create a Bar chart with data of multiple shapes should work with binary serialization
37 y = np.array([[0, 1], [1, 0, -1]], dtype=object)
38 bars = bqplot.Bars(x=[0, 1], y=y, scales=scales)
39
40 bars = bqplot.Bars(x=[0, 1], y=[[1, 2], [3, 4]], scales=scales)
41 state = bars.get_state()
42
43 bars2 = bqplot.Bars(scales=scales)
44 bars2.set_state(state)
45 assert bars.x[0] == 0
46 assert bars.x[1] == 1
47 assert bars.y[0][0] == 1
48 assert bars.y[0][1] == 2
49 assert bars.y[1][0] == 3
50 assert bars.y[1][1] == 4