Skip to content

Commit

Permalink
Merge pull request #89 from spotify/Release-3.0.1
Browse files Browse the repository at this point in the history
Added reference level point estimate to hover box of difference plots
  • Loading branch information
iampelle authored Apr 21, 2023
2 parents 1b43ec4 + c821056 commit af091a3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
History
=======

3.0.1 (2023-04-20)
------------------
* Added reference level point estimate to the hover box of difference plots

3.0.0 (2023-03-24)
------------------
* Dropped support for python 3.6
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Spotify Confidence
========

![Status](https://img.shields.io/badge/Status-Beta-blue.svg)
![Latest release](https://img.shields.io/badge/release-3.0.0-green.svg "Latest release: 3.0.0")
![Python](https://img.shields.io/badge/Python-3.6-blue.svg "Python")
![Latest release](https://img.shields.io/badge/release-3.0.1-green.svg "Latest release: 3.0.1")
![Python](https://img.shields.io/badge/Python-3.7-blue.svg "Python")
![Python](https://img.shields.io/badge/Python-3.8-blue.svg "Python")
![Python](https://img.shields.io/badge/Python-3.9-blue.svg "Python")
![Python](https://img.shields.io/badge/Python-3.10-blue.svg "Python")

Python library for AB test analysis.

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = spotify-confidence
version = 3.0.0
version = 3.0.1
author = Per Sillren
author_email = [email protected]
description = Package for calculating and visualising confidence intervals, e.g. for A/B test analysis.
Expand All @@ -24,7 +24,7 @@ install_requires =
scipy>=1.6.0,<1.8.0
pandas>=1.2.0,<2.0.0
statsmodels>=0.13.0,<1.0.0
chartify>=4.0.2
chartify>=4.0.3
ipywidgets>=8.0.0

[options.packages.find]
Expand Down
32 changes: 30 additions & 2 deletions spotify_confidence/analysis/frequentist/chartify_grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)
from ..constants import (
POINT_ESTIMATE,
ORIGINAL_POINT_ESTIMATE,
DIFFERENCE,
CI_LOWER,
CI_UPPER,
Expand All @@ -43,6 +44,7 @@
NIM,
NIM_TYPE,
PREFERENCE,
SFX1,
)
from ...chartgrid import ChartGrid

Expand Down Expand Up @@ -184,7 +186,7 @@ def _ordinal_difference_plot(

y_axis_label = self._get_difference_plot_label(absolute)
ch = self._ordinal_plot(
"difference",
DIFFERENCE,
difference_df,
groupby=None,
level_name="",
Expand Down Expand Up @@ -381,6 +383,8 @@ def _ordinal_plot(
y_column=center_name,
color_column=colors,
)
# Also plot transparent circles, just to be able to show hover box
ch.figure.line(source=df, x=self._ordinal_group_column, y=center_name, name="center", line_alpha=0)
ch.style.color_palette.reset_palette_order()
ch.plot.area(
data_frame=(
Expand All @@ -403,6 +407,15 @@ def _ordinal_plot(
line_dash="dashed",
line_width=1,
)
# Also plot named transparent line, just to be able to show hover box
ch.figure.line(
source=df.sort_values(self._ordinal_group_column),
x=self._ordinal_group_column,
y=NULL_HYPOTHESIS,
line_width=3,
line_alpha=0,
name="nim",
)
ch.axes.set_yaxis_label(y_axis_label)
ch.axes.set_xaxis_label(self._ordinal_group_column)
ch.set_source_label("")
Expand Down Expand Up @@ -553,9 +566,11 @@ def add_ci_to_chart_datasources(
data["color"] = np.array(df[group_col][index])
if DIFFERENCE in data.keys() or NULL_HYPOTHESIS in data.keys():
index = data["index"]
data["reference_level"] = np.array(df["level_1"][index])
data[DIFFERENCE] = np.array(df[DIFFERENCE][index])
data["p_value"] = np.array(df[P_VALUE][index])
data["adjusted_p"] = np.array(df[ADJUSTED_P][index])
data["reference_level_avg"] = np.array(df[ORIGINAL_POINT_ESTIMATE + SFX1][index])
if NULL_HYPOTHESIS in df.columns:
data["null_hyp"] = np.array(df[NULL_HYPOTHESIS][index])

Expand All @@ -580,6 +595,13 @@ def add_tools(
absolute=absolute,
extra_zeros=2,
)
axis_format_reference_level, _, _ = axis_format_precision(
numbers=concat(
[df[LOWER], df[center_name], df[UPPER], df[NULL_HYPOTHESIS] if NULL_HYPOTHESIS in df.columns else None]
),
absolute=True,
extra_zeros=2,
)
ordinal_tool_tip = [] if not ordinal else [(self._ordinal_group_column, f"@{self._ordinal_group_column}")]
p_value_tool_tip = (
(
Expand All @@ -590,8 +612,14 @@ def add_tools(
else []
)
nim_tool_tip = [("null hypothesis", f"@null_hyp{{{axis_format}}}")] if NULL_HYPOTHESIS in df.columns else []
reference_level_tool_tip = (
[("reference level", f"@reference_level: @reference_level_avg{{{axis_format_reference_level}}}")]
if "level_1" in df.columns
else []
)
tooltips = (
[("group", "@color")]
+ reference_level_tool_tip
+ ordinal_tool_tip
+ [(f"{center_name}", f"@{center_name}{{{axis_format}}}")]
+ [
Expand All @@ -603,7 +631,7 @@ def add_tools(
+ p_value_tool_tip
+ nim_tool_tip
)
lines_with_hover = [] if ordinal else ["center", "nim"]
lines_with_hover = ["center", "nim"]
renderers = [r for r in chart.figure.renderers if r.name in lines_with_hover]
hover = tools.HoverTool(tooltips=tooltips, renderers=renderers)

Expand Down
4 changes: 3 additions & 1 deletion spotify_confidence/analysis/frequentist/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def difference_plot(
groupby=groupby,
non_inferiority_margins=non_inferiority_margins,
final_expected_sample_size_column=final_expected_sample_size_column,
verbose=True,
)
chartgrid = self._confidence_grapher.plot_difference(
difference_df, absolute, groupby, non_inferiority_margins, use_adjusted_intervals, split_plot_by_groups
Expand All @@ -217,7 +218,7 @@ def differences_plot(
split_plot_by_groups: bool = False,
) -> ChartGrid:
difference_df = self.differences(
levels, absolute, groupby, non_inferiority_margins, final_expected_sample_size_column
levels, absolute, groupby, non_inferiority_margins, final_expected_sample_size_column, verbose=True
)
chartgrid = self._confidence_grapher.plot_differences(
difference_df, absolute, groupby, non_inferiority_margins, use_adjusted_intervals, split_plot_by_groups
Expand All @@ -242,6 +243,7 @@ def multiple_difference_plot(
level_as_reference=level_as_reference,
non_inferiority_margins=non_inferiority_margins,
final_expected_sample_size_column=final_expected_sample_size_column,
verbose=True,
)
chartgrid = self._confidence_grapher.plot_multiple_difference(
difference_df,
Expand Down

0 comments on commit af091a3

Please sign in to comment.