|
| 1 | +from __future__ import absolute_import |
| 2 | + |
| 3 | +from unittest import TestCase |
| 4 | + |
| 5 | +from plotly.graph_objs import * |
| 6 | + |
| 7 | + |
| 8 | +class TestToDataframe(TestCase): |
| 9 | + |
| 10 | + fig = None |
| 11 | + |
| 12 | + def setUp(self): |
| 13 | + super(TestToDataframe, self).setUp() |
| 14 | + self.fig = Figure( |
| 15 | + data=Data([ |
| 16 | + Scatter( |
| 17 | + x=[52698, 43117], |
| 18 | + y=[53, 31], |
| 19 | + mode='markers', |
| 20 | + name='North America', |
| 21 | + text=['United States', 'Canada'], |
| 22 | + marker=Marker( |
| 23 | + color='rgb(164, 194, 244)', |
| 24 | + size=12, |
| 25 | + line=Line( |
| 26 | + color='white', |
| 27 | + width=0.5 |
| 28 | + ) |
| 29 | + ) |
| 30 | + ), |
| 31 | + Scatter( |
| 32 | + x=[39317, 37236, 35650, 30066, 29570, 27159, 23557, 21046, |
| 33 | + 18007], |
| 34 | + y=[33, 20, 13, 19, 27, 19, 49, 44, 38], |
| 35 | + mode='markers', |
| 36 | + name='Europe', |
| 37 | + text=['Germany', 'Britain', 'France', 'Spain', 'Italy', |
| 38 | + 'Czech Rep.', 'Greece', 'Poland'], |
| 39 | + marker=Marker( |
| 40 | + color='rgb(255, 217, 102)', |
| 41 | + size=12, |
| 42 | + line=Line( |
| 43 | + color='white', |
| 44 | + width=0.5 |
| 45 | + ) |
| 46 | + ) |
| 47 | + ), |
| 48 | + Scatter( |
| 49 | + x=[42952, 37037, 33106, 17478, 9813, 5253, 4692, 3899], |
| 50 | + y=[23, 42, 54, 89, 14, 99, 93, 70], |
| 51 | + mode='markers', |
| 52 | + name='Asia/Pacific', |
| 53 | + text=['Australia', 'Japan', 'South Korea', 'Malaysia', |
| 54 | + 'China', 'Indonesia', 'Philippines', 'India'], |
| 55 | + marker=Marker( |
| 56 | + color='rgb(234, 153, 153)', |
| 57 | + size=12, |
| 58 | + line=Line( |
| 59 | + color='white', |
| 60 | + width=0.5 |
| 61 | + ) |
| 62 | + ) |
| 63 | + ), |
| 64 | + Scatter( |
| 65 | + x=[19097, 18601, 15595, 13546, 12026, 7434, 5419], |
| 66 | + y=[43, 47, 56, 80, 86, 93, 80], |
| 67 | + mode='markers', |
| 68 | + name='Latin America', |
| 69 | + text=['Chile', 'Argentina', 'Mexico', 'Venezuela', |
| 70 | + 'Venezuela', 'El Salvador', 'Bolivia'], |
| 71 | + marker=Marker( |
| 72 | + color='rgb(142, 124, 195)', |
| 73 | + size=12, |
| 74 | + line=Line( |
| 75 | + color='white', |
| 76 | + width=0.5 |
| 77 | + ) |
| 78 | + ) |
| 79 | + ) |
| 80 | + ]), |
| 81 | + layout=Layout( |
| 82 | + title='Quarter 1 Growth', |
| 83 | + autosize=False, |
| 84 | + width=500, |
| 85 | + height=500, |
| 86 | + xaxis=XAxis( |
| 87 | + title='GDP per Capita', |
| 88 | + showgrid=False, |
| 89 | + zeroline=False |
| 90 | + ), |
| 91 | + yaxis=YAxis( |
| 92 | + title='Percent', |
| 93 | + showline=False |
| 94 | + ), |
| 95 | + margin=Margin( |
| 96 | + l=65, |
| 97 | + r=50, |
| 98 | + b=65, |
| 99 | + t=90 |
| 100 | + ) |
| 101 | + ) |
| 102 | + ) |
| 103 | + |
| 104 | + def test_figure_to_dataframe(self): |
| 105 | + df = self.fig.to_dataframe() |
| 106 | + self.assertEqual(len(df), 9) |
| 107 | + self.assertEqual(len(df.columns), 12) |
0 commit comments