Skip to content

Commit 963f5a2

Browse files
committed
Add warning for mixed columns
1 parent 127ff95 commit 963f5a2

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

xarray_plotly/plotting.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import warnings
78
from typing import TYPE_CHECKING, Any
89

910
import numpy as np
@@ -211,16 +212,28 @@ def _style_traces_as_bars(fig: go.Figure) -> None:
211212

212213
# Build classification map
213214
class_map: dict[str, str] = {}
215+
mixed_traces: list[str] = []
214216
for name, flags in sign_flags.items():
215217
if flags["has_pos"] and flags["has_neg"]:
216218
class_map[name] = "mixed"
219+
mixed_traces.append(name)
217220
elif flags["has_neg"]:
218221
class_map[name] = "negative"
219222
elif flags["has_pos"]:
220223
class_map[name] = "positive"
221224
else:
222225
class_map[name] = "zero"
223226

227+
# Warn about mixed traces
228+
if mixed_traces:
229+
warnings.warn(
230+
f"fast_bar: traces {mixed_traces} have mixed positive/negative values "
231+
"and cannot be stacked. They are shown as dashed lines. "
232+
"Consider using bar() for proper stacking of mixed data.",
233+
UserWarning,
234+
stacklevel=3,
235+
)
236+
224237
# Apply styling to all traces
225238
for trace in all_traces:
226239
color = trace.line.color

0 commit comments

Comments
 (0)