Skip to content

Commit d57d035

Browse files
extra comments and another test
1 parent 48e56ef commit d57d035

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77

88
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+
913
df = pd.DataFrame(dict(a=[1, 2, 3], b=[4, 5, 6], c=[7, 8, 9]), index=[11, 12, 13])
1014
for px_fn in [px.scatter, px.line, px.area, px.bar]:
1115
fig = px_fn(df)
@@ -54,6 +58,7 @@ def test_wide_mode_external():
5458

5559

5660
def test_wide_mode_labels_external():
61+
# here we prove that the _uglylabels_ can be renamed using the usual labels kwarg
5762
df = pd.DataFrame(dict(a=[1, 2, 3], b=[4, 5, 6], c=[7, 8, 9]), index=[11, 12, 13])
5863
fig = px.bar(df)
5964
assert fig.layout.xaxis.title.text == "index"
@@ -73,6 +78,13 @@ def test_wide_mode_labels_external():
7378

7479

7580
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+
7688
df_in = pd.DataFrame(dict(a=[1, 2, 3], b=[4, 5, 6]), index=[11, 12, 13])
7789

7890
def extract_and_check_df(args_out):
@@ -123,6 +135,11 @@ def extract_and_check_df(args_out):
123135

124136

125137
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+
126143
def assert_df_and_args(df_in, args_in, args_expect, df_expect):
127144
args_in["data_frame"] = df_in
128145
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):
405422
)
406423
),
407424
)
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

Comments
 (0)