Skip to content

Commit 73771de

Browse files
authored
Merge branch 'master' into add-new-traces-to-templategen
2 parents cd6c101 + 817fef7 commit 73771de

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

packages/python/plotly/plotly/express/_core.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,6 @@ def set_cartesian_axis_opts(args, axis, letter, orders):
652652

653653

654654
def configure_cartesian_marginal_axes(args, fig, orders):
655-
if "histogram" in [args["marginal_x"], args["marginal_y"]]:
656-
fig.layout["barmode"] = "overlay"
657-
658655
nrows = len(fig._grid_ref)
659656
ncols = len(fig._grid_ref[0])
660657

@@ -1489,25 +1486,21 @@ def build_dataframe(args, constructor):
14891486
# PySpark to pandas.
14901487
is_pd_like = False
14911488

1492-
# Flag that indicates if data_frame requires to be converted to arrow via the
1493-
# dataframe interchange protocol.
1494-
# True if Ibis, DuckDB, Vaex or implements __dataframe__
1489+
# Flag that indicates if data_frame needs to be converted to PyArrow.
1490+
# True if Ibis, DuckDB, Vaex, or implements __dataframe__
14951491
needs_interchanging = False
14961492

14971493
# If data_frame is provided, we parse it into a narwhals DataFrame, while accounting
14981494
# for compatibility with pandas specific paths (e.g. Index/MultiIndex case).
14991495
if df_provided:
1500-
15011496
# data_frame is pandas-like DataFrame (pandas, modin.pandas, cudf)
15021497
if nw.dependencies.is_pandas_like_dataframe(args["data_frame"]):
1503-
15041498
columns = args["data_frame"].columns # This can be multi index
15051499
args["data_frame"] = nw.from_native(args["data_frame"], eager_only=True)
15061500
is_pd_like = True
15071501

15081502
# data_frame is pandas-like Series (pandas, modin.pandas, cudf)
15091503
elif nw.dependencies.is_pandas_like_series(args["data_frame"]):
1510-
15111504
args["data_frame"] = nw.from_native(
15121505
args["data_frame"], series_only=True
15131506
).to_frame()
@@ -1861,7 +1854,6 @@ def _check_dataframe_all_leaves(df: nw.DataFrame) -> None:
18611854
for row_idx, row in zip(
18621855
null_indices_mask, null_mask.filter(null_indices_mask).iter_rows()
18631856
):
1864-
18651857
i = row.index(True)
18661858

18671859
if not all(row[i:]):
@@ -1990,7 +1982,6 @@ def process_dataframe_hierarchy(args):
19901982

19911983
if args["color"]:
19921984
if discrete_color:
1993-
19941985
discrete_aggs.append(args["color"])
19951986
agg_f[args["color"]] = nw.col(args["color"]).max()
19961987
agg_f[f'{args["color"]}{n_unique_token}'] = (
@@ -2045,7 +2036,6 @@ def post_agg(dframe: nw.LazyFrame, continuous_aggs, discrete_aggs) -> nw.LazyFra
20452036
).drop([f"{col}{n_unique_token}" for col in discrete_aggs])
20462037

20472038
for i, level in enumerate(path):
2048-
20492039
dfg = (
20502040
df.group_by(path[i:], drop_null_keys=True)
20512041
.agg(**agg_f)
@@ -2487,6 +2477,10 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
24872477
constructor = go.Bar
24882478
args = process_dataframe_timeline(args)
24892479

2480+
# If we have marginal histograms, set barmode to "overlay"
2481+
if "histogram" in [args.get("marginal_x"), args.get("marginal_y")]:
2482+
layout_patch["barmode"] = "overlay"
2483+
24902484
trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
24912485
args, constructor, trace_patch, layout_patch
24922486
)
@@ -2558,7 +2552,12 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
25582552
legendgroup=trace_name,
25592553
showlegend=(trace_name != "" and trace_name not in trace_names),
25602554
)
2561-
if trace_spec.constructor in [go.Bar, go.Violin, go.Box, go.Histogram]:
2555+
2556+
# Set 'offsetgroup' only in group barmode (or if no barmode is set)
2557+
barmode = layout_patch.get("barmode")
2558+
if trace_spec.constructor in [go.Bar, go.Box, go.Violin, go.Histogram] and (
2559+
barmode == "group" or barmode is None
2560+
):
25622561
trace.update(alignmentgroup=True, offsetgroup=trace_name)
25632562
trace_names.add(trace_name)
25642563

packages/python/plotly/plotly/tests/test_optional/test_utils/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def np_inf():
9595
columns=["col 1"], data=[1, 2, 3, dt(2014, 1, 5), pd.NaT, np_nan(), np_inf()]
9696
)
9797

98-
rng = pd.date_range("1/1/2011", periods=2, freq="H")
98+
rng = pd.date_range("1/1/2011", periods=2, freq="h")
9999
ts = pd.Series([1.5, 2.5], index=rng)
100100

101101

0 commit comments

Comments
 (0)