Skip to content
Merged
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 @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix `mpl_to_plotly` showing unwanted legends with placeholder or internal label entries (`_nolegend_`, `_childN`) by defaulting `layout.showlegend=False` unless the matplotlib figure explicitly defines a legend [[#5699](https://github.com/plotly/plotly.py/pull/5699)], with thanks to @robertoffmoura for the contribution!
- Fix `mpl_to_plotly` crashing on figures with fully transparent or alpha-carrying colors, such as boxplot outlier markers (`facecolor="none"`), rgba line colors, and `color="none"` text and axis labels; all matplotlib colors are now exported through a single helper that maps `"none"` to transparent rgba and keeps or overrides alpha as matplotlib does [[#5700](https://github.com/plotly/plotly.py/pull/5700)], with thanks to @robertoffmoura for the contribution!
- Export tick label colors to the plotly tickfont in `mpl_to_plotly` [[#5716](https://github.com/plotly/plotly.py/pull/5716)], with thanks to @robertoffmoura for the contribution!
- Fix Plotly Express mutating lists passed to the `x` or `y` arguments in wide mode [[#5727](https://github.com/plotly/plotly.py/pull/5727)], with thanks to @cpruijsen for the contribution!
- Fix `px.sunburst`, `px.treemap` and `px.icicle` listing sectors in a different order on every run when `path` is used with a Polars DataFrame; sectors now follow their order of first appearance for all dataframe backends [[#5766](https://github.com/plotly/plotly.py/pull/5766)], with thanks to @Irahan2 for the contribution!
- Fix `mpl_to_plotly` conversion of matplotlib contour lines and line collections: close contour rings ending with `Z` codes, support dash styles, convert date x-axes, separate disjoint subpaths with `None` separators, hide line collection traces from the legend by default, and group consecutive same-style lines into single traces [[#5770](https://github.com/plotly/plotly.py/pull/5770)], with thanks to @robertoffmoura for the contribution!

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 object passed 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
10 changes: 10 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,13 @@ 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
# integer column names, as in the issue: string names are a no-op here
df = pd.DataFrame([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
for arg in ["x", "y"]:
cols = [0, 1]
px.bar(df, **{arg: cols})
assert cols == [0, 1]
Loading