44
55import holoviews as hv
66from holoviews .streams import Buffer
7- from holoviews .testing import assert_data_equal
87
98from .test_plot import TestBokehPlot , bokeh_renderer
109
@@ -16,8 +15,12 @@ def test_spread_stream_data(self):
1615 plot = bokeh_renderer .get_plot (dmap )
1716 buffer .send ({"y" : [1 , 2 , 1 , 4 ], "yerror" : [0.5 , 0.2 , 0.1 , 0.5 ], "x" : [0 , 1 , 2 , 3 ]})
1817 cds = plot .handles ["cds" ]
19- assert_data_equal (cds .data ["x" ], np .array ([0.0 , 1.0 , 2.0 , 3.0 , 3.0 , 2.0 , 1.0 , 0.0 ]))
20- assert_data_equal (cds .data ["y" ], np .array ([0.5 , 1.8 , 0.9 , 3.5 , 4.5 , 1.1 , 2.2 , 1.5 ]))
18+ np .testing .assert_array_equal (
19+ cds .data ["x" ], np .array ([0.0 , 1.0 , 2.0 , 3.0 , 3.0 , 2.0 , 1.0 , 0.0 ])
20+ )
21+ np .testing .assert_array_equal (
22+ cds .data ["y" ], np .array ([0.5 , 1.8 , 0.9 , 3.5 , 4.5 , 1.1 , 2.2 , 1.5 ])
23+ )
2124
2225 def test_spread_with_nans (self ):
2326 spread = hv .Spread (
@@ -34,11 +37,11 @@ def test_spread_with_nans(self):
3437 )
3538 plot = bokeh_renderer .get_plot (spread )
3639 cds = plot .handles ["cds" ]
37- assert_data_equal (
40+ np . testing . assert_array_equal (
3841 cds .data ["x" ],
3942 np .array ([0.0 , 1.0 , 2.0 , 2.0 , 1.0 , 0.0 , np .nan , 4.0 , 5.0 , 6.0 , 6.0 , 5.0 , 4.0 ]),
4043 )
41- assert_data_equal (
44+ np . testing . assert_array_equal (
4245 cds .data ["y" ],
4346 np .array ([0.0 , 0.0 , 0.0 , 3.0 , 2.0 , 1.0 , np .nan , 0.0 , 0.0 , 0.0 , 7.0 , 6.0 , 5.0 ]),
4447 )
@@ -111,3 +114,61 @@ def test_spread_padding_logy(self):
111114 assert x_range .end == 3.2
112115 assert y_range .start == 0.41158562699652224
113116 assert y_range .end == 4.2518491541367327
117+
118+ def test_spread_datetime_x (self ):
119+ dates = np .array (["2020-01-01" , "2020-01-02" , "2020-01-03" ], dtype = "datetime64[ns]" )
120+ spread = hv .Spread ((dates , [1.0 , 2.0 , 3.0 ], [0.5 , 0.5 , 0.5 ]))
121+ plot = bokeh_renderer .get_plot (spread )
122+ cds = plot .handles ["cds" ]
123+ expected_x = np .array (
124+ ["2020-01-01" , "2020-01-02" , "2020-01-03" , "2020-01-03" , "2020-01-02" , "2020-01-01" ],
125+ dtype = "datetime64[ns]" ,
126+ )
127+ expected_y = np .array ([0.5 , 1.5 , 2.5 , 3.5 , 2.5 , 1.5 ])
128+ np .testing .assert_array_equal (cds .data ["x" ], expected_x )
129+ np .testing .assert_array_equal (cds .data ["y" ], expected_y )
130+
131+ def test_spread_datetime_x_with_nat (self ):
132+ dates = np .array (
133+ ["2020-01-01" , "2020-01-02" , "NaT" , "2020-01-04" , "2020-01-05" ], dtype = "datetime64[ns]"
134+ )
135+ spread = hv .Spread ((dates , [1.0 , 2.0 , np .nan , 4.0 , 5.0 ], [0.5 , 0.5 , np .nan , 0.5 , 0.5 ]))
136+ plot = bokeh_renderer .get_plot (spread )
137+ cds = plot .handles ["cds" ]
138+ expected_x = np .array (
139+ [
140+ "2020-01-01" ,
141+ "2020-01-02" ,
142+ "2020-01-02" ,
143+ "2020-01-01" ,
144+ "NaT" ,
145+ "2020-01-04" ,
146+ "2020-01-05" ,
147+ "2020-01-05" ,
148+ "2020-01-04" ,
149+ ],
150+ dtype = "datetime64[ns]" ,
151+ )
152+ expected_y = np .array ([0.5 , 1.5 , 2.5 , 1.5 , np .nan , 3.5 , 4.5 , 5.5 , 4.5 ])
153+ np .testing .assert_array_equal (cds .data ["x" ], expected_x )
154+ np .testing .assert_array_equal (cds .data ["y" ], expected_y )
155+
156+ def test_spread_timedelta_x (self ):
157+ tds = np .array ([0 , 1 , 2 ], dtype = "timedelta64[D]" )
158+ spread = hv .Spread ((tds , [1.0 , 2.0 , 3.0 ], [0.5 , 0.5 , 0.5 ]))
159+ plot = bokeh_renderer .get_plot (spread )
160+ cds = plot .handles ["cds" ]
161+ expected_x = np .array ([0 , 1 , 2 , 2 , 1 , 0 ], dtype = "timedelta64[D]" )
162+ expected_y = np .array ([0.5 , 1.5 , 2.5 , 3.5 , 2.5 , 1.5 ])
163+ np .testing .assert_array_equal (cds .data ["x" ], expected_x )
164+ np .testing .assert_array_equal (cds .data ["y" ], expected_y )
165+
166+ def test_spread_timedelta_x_with_nat (self ):
167+ tds = np .array ([0 , 1 , "NaT" , 3 , 4 ], dtype = "timedelta64[D]" )
168+ spread = hv .Spread ((tds , [1.0 , 2.0 , np .nan , 4.0 , 5.0 ], [0.5 , 0.5 , np .nan , 0.5 , 0.5 ]))
169+ plot = bokeh_renderer .get_plot (spread )
170+ cds = plot .handles ["cds" ]
171+ expected_x = np .array ([0 , 1 , 1 , 0 , "NaT" , 3 , 4 , 4 , 3 ], dtype = "timedelta64[D]" )
172+ expected_y = np .array ([0.5 , 1.5 , 2.5 , 1.5 , np .nan , 3.5 , 4.5 , 5.5 , 4.5 ])
173+ np .testing .assert_array_equal (cds .data ["x" ], expected_x )
174+ np .testing .assert_array_equal (cds .data ["y" ], expected_y )
0 commit comments