@@ -17,6 +17,17 @@ def test_skip_hover():
1717 assert fig .data [0 ].hovertemplate == "species_id=%{marker.size}<extra></extra>"
1818
1919
20+ def test_hover_data_string_column ():
21+ df = px .data .tips ()
22+ fig = px .scatter (
23+ df ,
24+ x = "tip" ,
25+ y = "total_bill" ,
26+ hover_data = "sex" ,
27+ )
28+ assert "sex" in fig .data [0 ].hovertemplate
29+
30+
2031def test_composite_hover ():
2132 df = px .data .tips ()
2233 hover_dict = OrderedDict (
@@ -89,17 +100,20 @@ def test_formatted_hover_and_labels():
89100
90101
91102def test_fail_wrong_column ():
92- with pytest .raises (ValueError ) as err_msg :
93- px .scatter (
94- {"a" : [1 , 2 ], "b" : [3 , 4 ], "c" : [2 , 1 ]},
95- x = "a" ,
96- y = "b" ,
97- hover_data = {"d" : True },
103+ # Testing for each of bare string, list, and basic dictionary
104+ for hover_data_value in ["d" , ["d" ], {"d" : True }]:
105+ with pytest .raises (ValueError ) as err_msg :
106+ px .scatter (
107+ {"a" : [1 , 2 ], "b" : [3 , 4 ], "c" : [2 , 1 ]},
108+ x = "a" ,
109+ y = "b" ,
110+ hover_data = hover_data_value ,
111+ )
112+ assert (
113+ "Value of 'hover_data_0' is not the name of a column in 'data_frame'."
114+ in str (err_msg .value )
98115 )
99- assert (
100- "Value of 'hover_data_0' is not the name of a column in 'data_frame'."
101- in str (err_msg .value )
102- )
116+ # Testing other dictionary possibilities below
103117 with pytest .raises (ValueError ) as err_msg :
104118 px .scatter (
105119 {"a" : [1 , 2 ], "b" : [3 , 4 ], "c" : [2 , 1 ]},
0 commit comments