Skip to content

Commit

Permalink
☔ test pandas dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Aug 7, 2017
1 parent 60d5250 commit 9610008
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ dtvalue1 = [i[0] for i in dtvalue1]
dtvalue2 = [i[0] for i in dtvalue2]

bar = Bar('Bar chart', 'Profit and loss situation')
bar.add('profit', df1.index, df1.values)
bar.add('loss', df2.index, df2.values)
bar.add('profit', df1.index, dtvalue1)
bar.add('loss', df2.index, dtvalue2)
bar.render()
```
![usage-1](https://github.com/chenjiandongx/pyecharts/blob/master/images/usage-1.png)
Expand Down
29 changes: 26 additions & 3 deletions test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,34 @@ def test_embed_option():
assert "<body>" not in html


def test_numpy_array()
def test_numpy_array():
import numpy as np

title = "柱状图数据堆叠示例"
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = np.array([5, 20, 36, 10, 75, 90])
bar = Bar()
bar = Bar(title)
bar.add("商家A", attr, v1, is_stack=True)
bar.render_embed()
html = bar.render_embed()
json_encoded_title = json.dumps(title)
assert json_encoded_title in html


def test_pandas_dataframe():
import pandas as pd
import numpy as np

title = 'Bar chart'
index = pd.date_range('3/8/2017', periods=6, freq='M')
df1 = pd.DataFrame(np.random.randn(6), index=index)

df2 = pd.DataFrame(np.random.randn(6), index=index)

dtvalue1 = [i[0] for i in df1.values]
dtvalue2 = [i[0] for i in df2.values]

bar = Bar(title, 'Profit and loss situation')
bar.add('profit', df1.index, dtvalue1)
bar.add('loss', df2.index, dtvalue2)
html = bar.render_embed()
assert title in html

0 comments on commit 9610008

Please sign in to comment.