Skip to content

Commit a92e7dc

Browse files
committed
Test wide mode mutation with integer column names; reword comment
1 parent 756156d commit a92e7dc

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

‎plotly/express/_core.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ def build_dataframe(args, constructor):
16871687
args["wide_variable"] = args["y"] if wide_y else args["x"]
16881688
if df_provided and is_pd_like and args["wide_variable"] is columns:
16891689
var_name = columns.name
1690-
# copy into a new list so that the list provided by the user for
1690+
# copy into a new list so that the object passed by the user for
16911691
# x or y is not mutated when wide_variable's entries are replaced
16921692
args["wide_variable"] = list(args["wide_variable"])
16931693
if var_name in [None, "value", "index"] or (

‎tests/test_optional/test_px/test_px_wide.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,9 @@ def test_no_pd_perf_warning():
894894

895895
def test_wide_mode_does_not_mutate_x_or_y():
896896
# https://github.com/plotly/plotly.py/issues/4117
897-
df = pd.DataFrame(dict(a=[1, 2, 3], b=[4, 5, 6], c=[7, 8, 9]))
897+
# integer column names, as in the issue: string names are a no-op here
898+
df = pd.DataFrame([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
898899
for arg in ["x", "y"]:
899-
cols = ["a", "b"]
900+
cols = [0, 1]
900901
px.bar(df, **{arg: cols})
901-
assert cols == ["a", "b"]
902-
cols = [0, 1]
903-
df_int = pd.DataFrame([[1, 2], [3, 4]])
904-
px.histogram(df_int, x=cols)
905-
assert cols == [0, 1]
902+
assert cols == [0, 1]

0 commit comments

Comments
 (0)