Skip to content

Commit 2eaea98

Browse files
accept indexes as wide-mode spec
1 parent de764ce commit 2eaea98

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/python/plotly/plotly/express/_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ def build_dataframe(args, constructor):
12411241
args["wide_variable"] = args["y"] if wide_y else args["x"]
12421242
if df_provided and args["wide_variable"] is df_input.columns:
12431243
var_name = df_input.columns.name
1244+
if isinstance(args["wide_variable"], pd.Index):
12441245
args["wide_variable"] = list(args["wide_variable"])
12451246
if var_name in [None, "value", "index"] or (
12461247
df_provided and var_name in df_input

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def append_special_case(df_in, args_in, args_expect, df_expect):
658658
dict(
659659
index=[7, 8, 7, 8],
660660
_value=[1, 2, 3, 4],
661-
variable=["b", "b", "value", "value",],
661+
variable=["b", "b", "value", "value"],
662662
)
663663
),
664664
)
@@ -675,6 +675,16 @@ def append_special_case(df_in, args_in, args_expect, df_expect):
675675
dict(c=[7, 8, 7, 8], d=["a", "a", "b", "b"], value=[1, 2, 3, 4])
676676
),
677677
)
678+
# y = columns
679+
df = pd.DataFrame(dict(a=[1, 2], b=[3, 4]), index=[7, 8])
680+
df.index.name = "c"
681+
df.columns.name = "d"
682+
append_special_case(
683+
df_in=df,
684+
args_in=dict(x=df.index, y=df.columns[:1], color=None),
685+
args_expect=dict(x="c", y="value", color="variable"),
686+
df_expect=pd.DataFrame(dict(c=[7, 8], variable=["a", "a"], value=[1, 2])),
687+
)
678688

679689

680690
@pytest.mark.parametrize("df_in, args_in, args_expect, df_expect", special_cases)

0 commit comments

Comments
 (0)