6
6
7
7
8
8
def test_wide_mode_external ():
9
+ # here we test this feature "black box" style by calling actual PX functions and
10
+ # inspecting the figure... this is important but clunky, and is mostly a smoke test
11
+ # allowing us to do more "white box" testing below
12
+
9
13
df = pd .DataFrame (dict (a = [1 , 2 , 3 ], b = [4 , 5 , 6 ], c = [7 , 8 , 9 ]), index = [11 , 12 , 13 ])
10
14
for px_fn in [px .scatter , px .line , px .area , px .bar ]:
11
15
fig = px_fn (df )
@@ -54,6 +58,7 @@ def test_wide_mode_external():
54
58
55
59
56
60
def test_wide_mode_labels_external ():
61
+ # here we prove that the _uglylabels_ can be renamed using the usual labels kwarg
57
62
df = pd .DataFrame (dict (a = [1 , 2 , 3 ], b = [4 , 5 , 6 ], c = [7 , 8 , 9 ]), index = [11 , 12 , 13 ])
58
63
fig = px .bar (df )
59
64
assert fig .layout .xaxis .title .text == "index"
@@ -73,6 +78,13 @@ def test_wide_mode_labels_external():
73
78
74
79
75
80
def test_wide_mode_internal ():
81
+ # here we do basic exhaustive testing of the various graph_object permutations
82
+ # via build_dataframe directly, which leads to more compact test code:
83
+ # we pass in args (which includes df) and look at how build_dataframe mutates
84
+ # both args and the df, and assume that since the rest of the downstream PX
85
+ # machinery has not wide-mode-specific code, and the tests above pass, that this is
86
+ # enough to prove things work
87
+
76
88
df_in = pd .DataFrame (dict (a = [1 , 2 , 3 ], b = [4 , 5 , 6 ]), index = [11 , 12 , 13 ])
77
89
78
90
def extract_and_check_df (args_out ):
@@ -123,6 +135,11 @@ def extract_and_check_df(args_out):
123
135
124
136
125
137
def test_wide_mode_internal_special_cases ():
138
+ # given all of the above tests, and given that the melt() code is not sensitive
139
+ # to the trace type, we can do all sorts of special-case testing just by focusing
140
+ # on build_dataframe(args, go.Scatter) for various values of args, and looking at
141
+ # how args and df get mutated
142
+
126
143
def assert_df_and_args (df_in , args_in , args_expect , df_expect ):
127
144
args_in ["data_frame" ] = df_in
128
145
args_out = build_dataframe (args_in , go .Scatter )
@@ -405,3 +422,23 @@ def assert_df_and_args(df_in, args_in, args_expect, df_expect):
405
422
)
406
423
),
407
424
)
425
+
426
+ # assigning a px.Constant: works
427
+ df = pd .DataFrame (dict (a = [1 , 2 ], b = [3 , 4 ]))
428
+ df .columns .name = "my_col_name"
429
+ df .index .name = "my_index_name"
430
+ assert_df_and_args (
431
+ df_in = df ,
432
+ args_in = dict (x = None , y = None , color = None , symbol = px .Constant (1 )),
433
+ args_expect = dict (
434
+ x = "my_index_name" , y = "_value_" , color = "my_col_name" , symbol = "symbol" ,
435
+ ),
436
+ df_expect = pd .DataFrame (
437
+ dict (
438
+ my_index_name = [0 , 1 , 0 , 1 ],
439
+ _value_ = [1 , 2 , 3 , 4 ],
440
+ my_col_name = ["a" , "a" , "b" , "b" ],
441
+ symbol = [1 , 1 , 1 , 1 ],
442
+ )
443
+ ),
444
+ )
0 commit comments