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

Skip to content

Commit 78d81d2

Browse files
committed
Add encode_as_pandas unit test.
1 parent 75fc406 commit 78d81d2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

plotly/tests/test_optional/test_utils/test_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ def tolist(self):
6363
res = utils.PlotlyJSONEncoder.encode_as_list(ObjWithAttr())
6464
self.assertEqual(res, expected_res)
6565

66+
def test_encode_as_pandas(self):
67+
68+
# should *fail* on things that are not specific pandas objects
69+
not_pandas = ['giraffe', 6, float('nan'), ['a', 'list']]
70+
for obj in not_pandas:
71+
self.assertRaises(utils.NotEncodable,
72+
utils.PlotlyJSONEncoder.encode_as_pandas, obj)
73+
74+
# should succeed when we've got specific pandas thingies
75+
res = utils.PlotlyJSONEncoder.encode_as_pandas(pd.NaT)
76+
self.assertIs(res, None)
77+
6678
## JSON encoding
6779
numeric_list = [1, 2, 3]
6880
np_list = np.array([1, 2, 3, np.NaN, np.NAN, np.Inf, dt(2014, 1, 5)])

0 commit comments

Comments
 (0)