Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b9dfdf

Browse files
committed
numpy dates, datetime.date tests
1 parent b517175 commit 2b9dfdf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

plotly/tests/test_optional/test_utils/test_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from nose.plugins.attrib import attr
44

55
from datetime import datetime as dt
6+
import datetime
67
import numpy as np
78
import json
89
import pandas as pd
@@ -77,6 +78,17 @@ def test_figure_json_encoding():
7778
dt(2014, 1, 5, 1, 1, 1, 1)]))
7879

7980

81+
def test_datetime_json_encoding():
82+
j1 = json.dumps(dt_list, cls=utils._plotlyJSONEncoder)
83+
assert(j1 == '["2014-01-05", '
84+
'"2014-01-05 01:01:01", '
85+
'"2014-01-05 01:01:01.000001"]')
86+
j2 = json.dumps({"x": dt_list}, cls=utils._plotlyJSONEncoder)
87+
assert(j2 == '{"x": ["2014-01-05", '
88+
'"2014-01-05 01:01:01", '
89+
'"2014-01-05 01:01:01.000001"]}')
90+
91+
8092
def test_pandas_json_encoding():
8193
j1 = json.dumps(df['col 1'], cls=utils._plotlyJSONEncoder)
8294
assert(j1 == '[1, 2, 3, "2014-01-05", null, NaN, Infinity]')
@@ -136,3 +148,17 @@ def test_masked_constants_example():
136148
cls=utils._plotlyJSONEncoder)
137149
assert(jy == '[-398.11793026999999, -398.11792966000002, '
138150
'-398.11786308000001, NaN]')
151+
152+
153+
def test_numpy_dates():
154+
a = np.arange(np.datetime64('2011-07-11'), np.datetime64('2011-07-18'))
155+
j1 = json.dumps(a, cls=utils._plotlyJSONEncoder)
156+
assert(j1 == '["2011-07-11", "2011-07-12", "2011-07-13", '
157+
'"2011-07-14", "2011-07-15", "2011-07-16", '
158+
'"2011-07-17"]')
159+
160+
161+
def test_datetime_dot_date():
162+
a = [datetime.date(2014, 1, 1), datetime.date(2014, 1, 2)]
163+
j1 = json.dumps(a, cls=utils._plotlyJSONEncoder)
164+
assert(j1 == '["2014-01-01", "2014-01-02"]')

0 commit comments

Comments
 (0)