Skip to content

Commit

Permalink
set line_group in wide mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaskruchten committed Jun 25, 2020
1 parent e281bc9 commit 351a3c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fixed special cases with `px.sunburst` and `px.treemap` with `path` input ([#2524](https://github.com/plotly/plotly.py/pull/2524))
- Fixed bug in `hover_data` argument of `px` functions, when the column name is changed with labels and `hover_data` is a dictionary setting up a specific format for the hover data ([#2544](https://github.com/plotly/plotly.py/pull/2544)).
- Made the Plotly Express `trendline` argument more robust and made it work with datetime `x` values ([#2554](https://github.com/plotly/plotly.py/pull/2554))
- `px.line` now sets `line_group=<variable>` in wide mode by default ([#2599](https://github.com/plotly/plotly.py/pull/2599))

## [4.8.1] - 2020-05-28

Expand Down
2 changes: 2 additions & 0 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,8 @@ def build_dataframe(args, constructor):
args["y" if orient_v else "x"] = value_name
if constructor != go.Histogram2d:
args["color"] = args["color"] or var_name
if "line_group" in args:
args["line_group"] = args["line_group"] or var_name
if constructor == go.Bar:
if _is_continuous(df_output, value_name):
args["x" if orient_v else "y"] = wide_cross_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,20 @@ def test_mixed_input_error(df):
"Plotly Express cannot process wide-form data with columns of different type"
in str(err_msg.value)
)


def test_line_group():
df = pd.DataFrame(
data={
"who": ["a", "a", "b", "b"],
"x": [0, 1, 0, 1],
"score": [1.0, 2, 3, 4],
"miss": [3.2, 2.5, 1.3, 1.5],
}
)
fig = px.line(df, x="x", y=["miss", "score"])
assert len(fig.data) == 2
fig = px.line(df, x="x", y=["miss", "score"], color="who")
assert len(fig.data) == 4
fig = px.scatter(df, x="x", y=["miss", "score"], color="who")
assert len(fig.data) == 2

0 comments on commit 351a3c2

Please sign in to comment.