Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding release 3.0.4 #103

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

3.0.4 (2023-10-12)
------------------
* Fixing so that other multiple correction methods than Bonferroni are applied correctly.


3.0.3 (2023-10-12)
------------------
* Relaxing version requirements for scipy and pandas to allow versions 2.x
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Spotify Confidence
========

![Status](https://img.shields.io/badge/Status-Beta-blue.svg)
![Latest release](https://img.shields.io/badge/release-3.0.3-green.svg "Latest release: 3.0.3")
![Latest release](https://img.shields.io/badge/release-3.0.3-green.svg "Latest release: 3.0.4")
![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")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = spotify-confidence
version = 3.0.3
version = 3.0.4
author = Per Sillren
author_email = pers@spotify.com
description = Package for calculating and visualising confidence intervals, e.g. for A/B test analysis.
Expand Down
14 changes: 8 additions & 6 deletions spotify_confidence/analysis/frequentist/chartify_grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ def _categorical_difference_chart(
df[~df[NIM].isna()]
.assign(
color_column=lambda df: df.apply(
lambda row: "red"
if row[LOWER] < row[NULL_HYPOTHESIS]
and row[PREFERENCE] == "increase"
or row[NULL_HYPOTHESIS] < row[UPPER]
and row[PREFERENCE] == "decrease"
else "green",
lambda row: (
"red"
if row[LOWER] < row[NULL_HYPOTHESIS]
and row[PREFERENCE] == "increase"
or row[NULL_HYPOTHESIS] < row[UPPER]
and row[PREFERENCE] == "decrease"
else "green"
),
axis=1,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,13 @@ def _add_variance_reduction_rate(df: DataFrame, **kwargs: Dict) -> DataFrame:


def _add_p_value(df: DataFrame, **kwargs: Dict) -> DataFrame:
return (
df.pipe(set_alpha_and_adjust_preference, **kwargs)
.assign(**{P_VALUE: lambda df: df.pipe(_p_value, **kwargs)})
return df.pipe(set_alpha_and_adjust_preference, **kwargs).assign(
**{P_VALUE: lambda df: df.pipe(_p_value, **kwargs)}
)


def _add_ci_and_adjust_if_absolute(df: DataFrame, **kwargs: Dict) -> DataFrame:
return (
df.pipe(add_ci, **kwargs)
.pipe(_adjust_if_absolute, absolute=kwargs[ABSOLUTE])
)
return df.pipe(add_ci, **kwargs).pipe(_adjust_if_absolute, absolute=kwargs[ABSOLUTE])


def _adjust_if_absolute(df: DataFrame, absolute: bool) -> DataFrame:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ def adjusted_alphas_for_group(grp: DataFrame) -> Series:
.assign(
**{
ADJUSTED_ALPHA: lambda df: df.apply(
lambda row: 2 * (1 - st.norm.cdf(row["zb"]))
if (grp[PREFERENCE_TEST] == TWO_SIDED).all()
else 1 - st.norm.cdf(row["zb"]),
lambda row: (
2 * (1 - st.norm.cdf(row["zb"]))
if (grp[PREFERENCE_TEST] == TWO_SIDED).all()
else 1 - st.norm.cdf(row["zb"])
),
axis=1,
)
}
Expand Down
17 changes: 6 additions & 11 deletions spotify_confidence/analysis/frequentist/multiple_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from pandas import DataFrame
from statsmodels.stats.multitest import multipletests

from spotify_confidence.analysis.confidence_utils import (
groupbyApplyParallel
)
from spotify_confidence.analysis.confidence_utils import groupbyApplyParallel
from spotify_confidence.analysis.constants import (
BONFERRONI,
BONFERRONI_ONLY_COUNT_TWOSIDED,
Expand Down Expand Up @@ -154,13 +152,10 @@ def add_adjusted_p_and_is_significant(df: DataFrame, **kwargs: Dict) -> DataFram
for column in df.index.names
if kwargs[ORDINAL_GROUP_COLUMN] is not None
and column is not None
and (column != kwargs[ORDINAL_GROUP_COLUMN]
or kwargs[FINAL_EXPECTED_SAMPLE_SIZE] is None)
and (column != kwargs[ORDINAL_GROUP_COLUMN] or kwargs[FINAL_EXPECTED_SAMPLE_SIZE] is None)
]
df = groupbyApplyParallel(
df.groupby(
groups_except_ordinal + [kwargs[METHOD], "level_1", "level_2"], as_index=False, sort=False
),
df.groupby(groups_except_ordinal + [kwargs[METHOD], "level_1", "level_2"], as_index=False, sort=False),
lambda df: compute_sequential_adjusted_alpha(df, **kwargs),
)
elif kwargs[CORRECTION_METHOD] in [
Expand Down Expand Up @@ -273,9 +268,9 @@ def set_alpha_and_adjust_preference(df: DataFrame, **kwargs: Dict) -> DataFrame:
return df.assign(
**{
ALPHA: df.apply(
lambda row: 2 * alpha_0
if kwargs[CORRECTION_METHOD] == SPOT_1 and row[PREFERENCE] != TWO_SIDED
else alpha_0,
lambda row: (
2 * alpha_0 if kwargs[CORRECTION_METHOD] == SPOT_1 and row[PREFERENCE] != TWO_SIDED else alpha_0
),
axis=1,
)
}
Expand Down
8 changes: 5 additions & 3 deletions spotify_confidence/analysis/frequentist/nims_and_mdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def add_nim_input_columns_from_tuple_or_dict(df, nims: NIM_TYPE, mde_column: str
elif nims is None or not nims:
return df.assign(**{NIM_COLUMN_DEFAULT: None}).assign(
**{
PREFERRED_DIRECTION_COLUMN_DEFAULT: None
if PREFERRED_DIRECTION_COLUMN_DEFAULT not in df or mde_column is None
else df[PREFERRED_DIRECTION_COLUMN_DEFAULT]
PREFERRED_DIRECTION_COLUMN_DEFAULT: (
None
if PREFERRED_DIRECTION_COLUMN_DEFAULT not in df or mde_column is None
else df[PREFERRED_DIRECTION_COLUMN_DEFAULT]
)
}
)
else:
Expand Down
8 changes: 4 additions & 4 deletions tests/frequentist/test_ztest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ def test_multiple_difference(self, correction_method):
BONFERRONI,
BONFERRONI_ONLY_COUNT_TWOSIDED,
BONFERRONI_DO_NOT_COUNT_NON_INFERIORITY,
SPOT_1
SPOT_1,
]:
difference_df = self.test.multiple_difference(
level=("control", 1), groupby="country", level_as_reference=True
Expand Down Expand Up @@ -1584,7 +1584,7 @@ def test_multiple_difference(self, correction_method):
_, adjusted_p, _, _ = multipletests(
pvals=difference_df["p-value"],
alpha=1 - self.test._confidence_computer._interval_size,
method=corr_method
method=corr_method,
)

assert np.allclose(
Expand All @@ -1600,7 +1600,7 @@ def test_multiple_difference_groupby(self, correction_method):
BONFERRONI,
BONFERRONI_ONLY_COUNT_TWOSIDED,
BONFERRONI_DO_NOT_COUNT_NON_INFERIORITY,
SPOT_1
SPOT_1,
]:
difference_df = self.test.multiple_difference(
level="control", groupby=["days_since_reg", "country"], level_as_reference=True
Expand Down Expand Up @@ -1640,7 +1640,7 @@ def test_multiple_difference_groupby(self, correction_method):
_, adjusted_p, _, _ = multipletests(
pvals=difference_df["p-value"],
alpha=1 - self.test._confidence_computer._interval_size,
method=corr_method
method=corr_method,
)

assert np.allclose(
Expand Down
Loading