Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix the sphinx-gallery scraper so that it generates thumbnails for figures shown with `fig.show()` or displayed as the last expression of a code block [[#5701](https://github.com/plotly/plotly.py/pull/5701)], with thanks to @larsoner for the contribution!
- The scaper now warns once (instead of failing the build) when static image export is unavailable
- The sphinx-gallery scraper no longer scrapes files belonging to other examples during parallel builds [[#5701](https://github.com/plotly/plotly.py/pull/5701)], with thanks to @larsoner for the contribution!
- Fix Plotly Express mutating lists passed to the `x` or `y` arguments in wide mode [[#4117](https://github.com/plotly/plotly.py/issues/4117)]

### Updated
- Update plotly.js from version 4.0.0 to version 4.1.1 [[#5722](https://github.com/plotly/plotly.py/pull/5722), [#5730](https://github.com/plotly/plotly.py/pull/5730)]. See the plotly.js release notes for [v4.1.0](https://github.com/plotly/plotly.js/releases/tag/v4.1.0) and [v4.1.1](https://github.com/plotly/plotly.js/releases/tag/v4.1.1) for details. Notable changes include:
Expand Down
5 changes: 3 additions & 2 deletions plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,9 @@ def build_dataframe(args, constructor):
args["wide_variable"] = args["y"] if wide_y else args["x"]
if df_provided and is_pd_like and args["wide_variable"] is columns:
var_name = columns.name
if is_pd_like and isinstance(args["wide_variable"], native_namespace.Index):
args["wide_variable"] = list(args["wide_variable"])
# copy into a new list so that the list provided by the user for
# x or y is not mutated when wide_variable's entries are replaced
args["wide_variable"] = list(args["wide_variable"])
if var_name in [None, "value", "index"] or (
df_provided and var_name in columns
):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_optional/test_px/test_px_wide.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,16 @@ def test_no_pd_perf_warning():
if issubclass(warn.category, pd.errors.PerformanceWarning)
]
assert len(performance_warnings) == 0, "PerformanceWarning(s) raised!"


def test_wide_mode_does_not_mutate_x_or_y():
# https://github.com/plotly/plotly.py/issues/4117
df = pd.DataFrame(dict(a=[1, 2, 3], b=[4, 5, 6], c=[7, 8, 9]))
for arg in ["x", "y"]:
cols = ["a", "b"]
px.bar(df, **{arg: cols})
assert cols == ["a", "b"]
cols = [0, 1]
df_int = pd.DataFrame([[1, 2], [3, 4]])
px.histogram(df_int, x=cols)
assert cols == [0, 1]