8000 Add unit test for encode_as_numpy. · MVReddy/python-api@111872e · GitHub
[go: up one dir, main page]

Skip to content

Commit 111872e

Browse files
committed
Add unit test for encode_as_numpy.
1 parent 78d81d2 commit 111872e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

plotly/tests/test_optional/test_utils/test_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from unittest import TestCase
66

7+
import math
78
from datetime import datetime as dt
89
import datetime
910
import numpy as np
@@ -75,6 +76,19 @@ def test_encode_as_pandas(self):
7576
res = utils.PlotlyJSONEncoder.encode_as_pandas(pd.NaT)
7677
self.assertIs(res, None)
7778

79+
def test_encode_as_numpy(self):
80+
81+
# should *fail* on non-numpy-y things
82+
not_numpy = ['hippo', 8, float('nan'), {'a': 'dict'}]
83+
for obj in not_numpy:
84+
self.assertRaises(utils.NotEncodable,
85+
utils.PlotlyJSONEncoder.encode_as_numpy, obj)
86+
87+
# should succeed with numpy-y-thingies
88+
res = utils.PlotlyJSONEncoder.encode_as_numpy(np.ma.core.masked)
89+
self.assertTrue(math.isnan(res))
90+
91+
7892
## JSON encoding
7993
numeric_list = [1, 2, 3]
8094
np_list = np.array([1, 2, 3, np.NaN, np.NAN, np.Inf, dt(2014, 1, 5)])

0 commit comments

Comments
 (0)
0