@@ -48,7 +48,7 @@ def test_is_col_list():
48
48
@pytest .mark .parametrize (
49
49
"px_fn" ,
50
50
[px .scatter , px .line , px .area , px .bar , px .violin , px .box , px .strip ]
51
- + [px .histogram , px .funnel ],
51
+ + [px .histogram , px .funnel , px . density_contour , px . density_heatmap ],
52
52
)
53
53
@pytest .mark .parametrize ("orientation" , [None , "v" , "h" ])
54
54
@pytest .mark .parametrize ("style" , ["implicit" , "explicit" ])
@@ -67,7 +67,7 @@ def test_wide_mode_external(px_fn, orientation, style):
67
67
if style == "implicit" :
68
68
fig = px_fn (df , orientation = orientation )
69
69
70
- if px_fn in [px .scatter , px .line , px .area , px .bar , px .funnel ]:
70
+ if px_fn in [px .scatter , px .line , px .area , px .bar , px .funnel , px . density_contour ]:
71
71
if style == "explicit" :
72
72
fig = px_fn (** {"data_frame" : df , y : list (df .columns ), x : df .index })
73
73
assert len (fig .data ) == 3
@@ -78,6 +78,14 @@ def test_wide_mode_external(px_fn, orientation, style):
78
78
assert fig .layout [xaxis ].title .text == "index"
79
79
assert fig .layout [yaxis ].title .text == "_value_"
80
80
assert fig .layout .legend .title .text == "_column_"
81
+ if px_fn in [px .density_heatmap ]:
82
+ if style == "explicit" :
83
+ fig = px_fn (** {"data_frame" : df , y : list (df .columns ), x : df .index })
84
+ assert len (fig .data ) == 1
85
+ assert list (fig .data [0 ][x ]) == [11 , 12 , 13 , 11 , 12 , 13 , 11 , 12 , 13 ]
86
+ assert list (fig .data [0 ][y ]) == [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
87
+ assert fig .layout [xaxis ].title .text == "index"
88
+ assert fig .layout [yaxis ].title .text == "_value_"
81
89
if px_fn in [px .violin , px .box , px .strip ]:
82
90
if style == "explicit" :
83
91
fig = px_fn (** {"data_frame" : df , y : list (df .columns )})
@@ -125,7 +133,10 @@ def test_wide_mode_labels_external():
125
133
"trace_type,x,y,color" ,
126
134
[
127
135
(go .Scatter , "index" , "_value_" , "_column_" ),
136
+ (go .Histogram2dContour , "index" , "_value_" , "_column_" ),
137
+ (go .Histogram2d , "index" , "_value_" , None ),
128
138
(go .Bar , "index" , "_value_" , "_column_" ),
139
+ (go .Funnel , "index" , "_value_" , "_column_" ),
129
140
(go .Box , "_column_" , "_value_" , None ),
130
141
(go .Violin , "_column_" , "_value_" , None ),
131
142
(go .Histogram , "_value_" , None , "_column_" ),
@@ -145,40 +156,43 @@ def test_wide_mode_internal(trace_type, x, y, color, orientation):
145
156
assert_frame_equal (
146
157
df_out .sort_index (axis = 1 ), pd .DataFrame (expected ).sort_index (axis = 1 ),
147
158
)
148
- if orientation is None or orientation == "v" :
149
- assert args_out == dict (x = x , y = y , color = color , orientation = "v" )
159
+ if trace_type in [go .Histogram2dContour , go .Histogram2d ]:
160
+ if orientation is None or orientation == "v" :
161
+ assert args_out == dict (x = x , y = y , color = color )
162
+ else :
163
+ assert args_out == dict (x = y , y = x , color = color )
150
164
else :
151
- assert args_out == dict (x = y , y = x , color = color , orientation = "h" )
165
+ if (orientation is None and trace_type != go .Funnel ) or orientation == "v" :
166
+ assert args_out == dict (x = x , y = y , color = color , orientation = "v" )
167
+ else :
168
+ assert args_out == dict (x = y , y = x , color = color , orientation = "h" )
152
169
153
170
154
171
cases = []
155
172
for transpose in [True , False ]:
156
- for tt in [go .Scatter , go .Bar , go .Funnel ]:
173
+ for tt in [go .Scatter , go .Bar , go .Funnel , go .Histogram2dContour , go .Histogram2d ]:
174
+ color = None if tt == go .Histogram2d else "_column_"
157
175
df_in = dict (a = [1 , 2 ], b = [3 , 4 ])
158
176
args = dict (x = None , y = ["a" , "b" ], color = None , orientation = None )
159
177
df_exp = dict (
160
178
_column_ = ["a" , "a" , "b" , "b" ], _value_ = [1 , 2 , 3 , 4 ], index = [0 , 1 , 0 , 1 ],
161
179
)
162
- cases .append (
163
- (tt , df_in , args , "index" , "_value_" , "_column_" , df_exp , transpose )
164
- )
180
+ cases .append ((tt , df_in , args , "index" , "_value_" , color , df_exp , transpose ))
165
181
166
182
df_in = dict (a = [1 , 2 ], b = [3 , 4 ], c = [5 , 6 ])
167
183
args = dict (x = "c" , y = ["a" , "b" ], color = None , orientation = None )
168
184
df_exp = dict (
169
185
_column_ = ["a" , "a" , "b" , "b" ], _value_ = [1 , 2 , 3 , 4 ], c = [5 , 6 , 5 , 6 ],
170
186
)
171
- cases .append ((tt , df_in , args , "c" , "_value_" , "_column_" , df_exp , transpose ))
187
+ cases .append ((tt , df_in , args , "c" , "_value_" , color , df_exp , transpose ))
172
188
173
189
args = dict (x = None , y = [[1 , 2 ], [3 , 4 ]], color = None , orientation = None )
174
190
df_exp = dict (
175
191
_column_ = ["_column__0" , "_column__0" , "_column__1" , "_column__1" ],
176
192
_value_ = [1 , 2 , 3 , 4 ],
177
193
index = [0 , 1 , 0 , 1 ],
178
194
)
179
- cases .append (
180
- (tt , None , args , "index" , "_value_" , "_column_" , df_exp , transpose )
181
- )
195
+ cases .append ((tt , None , args , "index" , "_value_" , color , df_exp , transpose ))
182
196
183
197
for tt in [go .Bar ]: # bar categorical exception
184
198
df_in = dict (a = ["q" , "r" ], b = ["s" , "t" ])
@@ -242,13 +256,16 @@ def test_wide_x_or_y(tt, df_in, args_in, x, y, color, df_out_exp, transpose):
242
256
args_out = build_dataframe (args_in , tt )
243
257
df_out = args_out .pop ("data_frame" ).sort_index (axis = 1 )
244
258
assert_frame_equal (df_out , pd .DataFrame (df_out_exp ).sort_index (axis = 1 ))
245
- orientation_exp = args_in ["orientation" ]
246
- if (args_in ["x" ] is None ) != (args_in ["y" ] is None ) and tt != go .Histogram :
247
- orientation_exp = "h" if transpose else "v"
248
259
if transpose :
249
- assert args_out == dict (x = y , y = x , color = color , orientation = orientation_exp )
260
+ args_exp = dict (x = y , y = x , color = color )
250
261
else :
251
- assert args_out == dict (x = x , y = y , color = color , orientation = orientation_exp )
262
+ args_exp = dict (x = x , y = y , color = color )
263
+ if tt not in [go .Histogram2dContour , go .Histogram2d ]:
264
+ orientation_exp = args_in ["orientation" ]
265
+ if (args_in ["x" ] is None ) != (args_in ["y" ] is None ) and tt != go .Histogram :
266
+ orientation_exp = "h" if transpose else "v"
267
+ args_exp ["orientation" ] = orientation_exp
268
+ assert args_out == args_exp
252
269
253
270
254
271
@pytest .mark .parametrize ("orientation" , [None , "v" , "h" ])
0 commit comments