|
3 | 3 | from nose.plugins.attrib import attr
|
4 | 4 |
|
5 | 5 | from datetime import datetime as dt
|
| 6 | +import datetime |
6 | 7 | import numpy as np
|
7 | 8 | import json
|
8 | 9 | import pandas as pd
|
@@ -77,6 +78,17 @@ def test_figure_json_encoding():
|
77 | 78 | dt(2014, 1, 5, 1, 1, 1, 1)]))
|
78 | 79 |
|
79 | 80 |
|
| 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 | + |
80 | 92 | def test_pandas_json_encoding():
|
81 | 93 | j1 = json.dumps(df['col 1'], cls=utils._plotlyJSONEncoder)
|
82 | 94 | assert(j1 == '[1, 2, 3, "2014-01-05", null, NaN, Infinity]')
|
@@ -136,3 +148,17 @@ def test_masked_constants_example():
|
136 | 148 | cls=utils._plotlyJSONEncoder)
|
137 | 149 | assert(jy == '[-398.11793026999999, -398.11792966000002, '
|
138 | 150 | '-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