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 @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Fix `mpl_to_plotly` not setting `paper_bgcolor` and `plot_bgcolor` from the matplotlib figure and axes backgrounds, so converted figures match the source figure's background colors [[#5285](https://github.com/plotly/plotly.py/pull/5285)], with thanks to @robertoffmoura for the contribution!
- Fix rendering issue causing a too-large div when calling `Figure.show()` in Google Colab [[#5718](https://github.com/plotly/plotly.py/pull/5718)]
- 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.0 [[#5722](https://github.com/plotly/plotly.py/pull/5722)]. See the [plotly.js release notes](https://github.com/plotly/plotly.js/releases/tag/v4.1.0) 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]