55
66from mplaltair import convert
77
8- df = pd .DataFrame ({'quant' : [1 , 1.5 , 2 ], 'ord' : [0 , 1 , 2 ], 'nom' : ['A' , 'B' , 'C' ]})
8+ df = pd .DataFrame ({
9+ 'quant' : [1 , 1.5 , 2 ],
10+ 'ord' : [0 , 1 , 2 ],
11+ 'nom' : ['A' , 'B' , 'C' ],
12+ 'temp' : [10 , 20 , 30 ]
13+ })
14+
15+ def test_encoding_not_provided ():
16+ chart_spec = alt .Chart (df ).mark_point ().to_dict ()
17+ with pytest .raises (ValueError ):
18+ convert (chart_spec )
19+
20+ def test_invalid_encodings ():
21+ chart_spec = alt .Chart (df ).encode (x2 = 'quant' ).mark_point ().to_dict ()
22+ with pytest .raises (ValueError ):
23+ convert (chart_spec )
924
1025@pytest .mark .parametrize ('channel' , ['quant' , 'ord' , 'nom' ])
1126def test_convert_x_success (channel ):
@@ -45,9 +60,9 @@ def test_convert_color_fail():
4560 with pytest .raises (KeyError ):
4661 convert (chart_spec )
4762
48- @pytest .mark .parametrize ('channel' , ['quant' , 'ord' ])
49- def test_convert_fill (channel ):
50- chart_spec = alt .Chart (df ).encode (fill = channel ).mark_point ().to_dict ()
63+ @pytest .mark .parametrize ('channel,type ' , [( 'quant' , 'Q' ), ( ' ord', 'O' ) ])
64+ def test_convert_fill (channel , type ):
65+ chart_spec = alt .Chart (df ).encode (fill = '{}:{}' . format ( channel , type ) ).mark_point ().to_dict ()
5166 mapping = convert (chart_spec )
5267 assert list (mapping ['c' ]) == list (df [channel ].values )
5368
@@ -56,14 +71,19 @@ def test_convert_fill_success_nominal():
5671 with pytest .raises (NotImplementedError ):
5772 convert (chart_spec )
5873
74+ def test_convert_fill_success_temporal ():
75+ chart_spec = alt .Chart (df ).encode (fill = 'temp:T' ).mark_point ().to_dict ()
76+ with pytest .raises (NotImplementedError ):
77+ convert (chart_spec )
78+
5979def test_convert_fill_fail ():
6080 chart_spec = alt .Chart (df ).encode (fill = 'b:N' ).mark_point ().to_dict ()
6181 with pytest .raises (KeyError ):
6282 convert (chart_spec )
6383
64- @pytest .mark .parametrize ('channel' , ['quant' , 'ord' ])
65- def test_convert_size_success (channel ):
66- chart_spec = alt .Chart (df ).encode (size = channel ).mark_point ().to_dict ()
84+ @pytest .mark .parametrize ('channel,type ' , [( 'quant' , 'Q' ), ( ' ord', 'O' ) ])
85+ def test_convert_size_success (channel , type ):
86+ chart_spec = alt .Chart (df ).encode (size = '{}:{}' . format ( channel , type ) ).mark_point ().to_dict ()
6787 mapping = convert (chart_spec )
6888 assert list (mapping ['s' ]) == list (df [channel ].values )
6989
@@ -72,6 +92,11 @@ def test_convert_size_success_nominal():
7292 with pytest .raises (NotImplementedError ):
7393 convert (chart_spec )
7494
95+ def test_convert_size_success_temporal ():
96+ chart_spec = alt .Chart (df ).encode (size = 'temp:T' ).mark_point ().to_dict ()
97+ with pytest .raises (NotImplementedError ):
98+ convert (chart_spec )
99+
75100def test_convert_size_fail ():
76101 chart_spec = alt .Chart (df ).encode (size = 'b:N' ).mark_point ().to_dict ()
77102 with pytest .raises (KeyError ):
0 commit comments