Skip to content

Commit de3591d

Browse files
committed
get_error_bars: handle plots with [0] in confidence arrays
1 parent 2d8d531 commit de3591d

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

metrics/domain/charts/common_charts/plots/bar/plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ def get_error_bars(
8989
# We may get some plots with confidence and some without so handle those
9090
# gracefully
9191
upper_values = [
92-
(confidence or metric) - metric
92+
(confidence if confidence is not None else metric) - metric
9393
for confidence, metric in zip(
9494
upper_confidence, plot_data.y_axis_values, strict=True
9595
)
9696
]
9797

9898
lower_values = [
99-
metric - (confidence or metric)
99+
metric - (confidence if confidence is not None else metric)
100100
for confidence, metric in zip(
101101
lower_confidence, plot_data.y_axis_values, strict=True
102102
)

tests/integration/metrics/domain/charts/bar/test_generation.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,45 @@ def test_confidence_intervals_missing_data_nones_in_values(
314314
assert main_bar_plot.error_y.array is not None
315315
assert main_bar_plot.error_y.arrayminus is not None
316316

317+
def test_confidence_intervals_missing_data_0_in_values(
318+
self, fake_plot_data: PlotGenerationData
319+
):
320+
# Given
321+
chart_plots_data = [fake_plot_data]
322+
chart_plots_data[0].parameters.chart_type = "bar"
323+
# Check that it works if there's a mix of 0 and Values
324+
fake_plot_data.additional_values = {
325+
"lower_confidence": [0] * len(fake_plot_data.y_axis_values),
326+
"upper_confidence": [2] * len(fake_plot_data.y_axis_values),
327+
}
328+
chart_payload = ChartGenerationPayload(
329+
chart_width=WIDTH,
330+
chart_height=HEIGHT,
331+
plots=chart_plots_data,
332+
x_axis_title="",
333+
y_axis_title="",
334+
y_axis_minimum_value=0,
335+
y_axis_maximum_value=None,
336+
confidence_intervals=True,
337+
confidence_colour="BLUE",
338+
)
339+
340+
# When
341+
figure: plotly.graph_objects.Figure = generate_chart_figure(
342+
chart_generation_payload=chart_payload
343+
)
344+
345+
# Then
346+
# There should be 1 plot for the bar plot
347+
assert len(figure.data) == 1
348+
349+
main_bar_plot: plotly.graph_objects.Bar = figure.data[0]
350+
# There should be a populated error object
351+
assert main_bar_plot.error_y.array is not None
352+
assert main_bar_plot.error_y.arrayminus == tuple(
353+
[value for value in fake_plot_data.y_axis_values]
354+
)
355+
317356
def test_x_axis_type_is_not_date(self, fake_plot_data: PlotGenerationData):
318357
"""
319358
Given a list of x and y values where x values are NOT dates

0 commit comments

Comments
 (0)