Skip to content
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
4 changes: 2 additions & 2 deletions jetstream/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,9 +1386,9 @@ def run(

segment_labels = ["all"] + [s.name for s in self.config.experiment.segments]
analysis_length_dates = 1
if period.value == AnalysisPeriod.OVERALL:
if period == AnalysisPeriod.OVERALL:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh enums can be so annoying in python.

analysis_length_dates = time_limits.analysis_length_dates
elif period.value == AnalysisPeriod.WEEK:
elif period == AnalysisPeriod.WEEK:
analysis_length_dates = 7

for analysis_basis in analysis_bases:
Expand Down
6 changes: 3 additions & 3 deletions jetstream/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def from_config(
continue
if pre_treatment.name() == pre_treatment_conf.name:
found = True
# inject analysis_period_length from experiment
pre_treatment.analysis_period_length = analysis_period_length or 1
pre_treatment_instance = pre_treatment.from_dict(pre_treatment_conf.args)
pre_treatment_instance.analysis_period_length = analysis_period_length or 1

pre_treatments.append(pre_treatment.from_dict(pre_treatment_conf.args))
pre_treatments.append(pre_treatment_instance)

if not found:
raise ValueError(f"Could not find pre-treatment {pre_treatment_conf.name}.")
Expand Down
29 changes: 29 additions & 0 deletions jetstream/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ def __repr__(self):


class TestStatistics:
def test_summary_from_config_injects_analysis_period_length(self):
"""normalize_over_analysis_period must receive the experiment's analysis period length
on the resulting pre-treatment instance. Otherwise values are divided by the default
of 1 (a no-op) and weekly/overall metrics are not scaled down."""
from metric_config_parser.metric import Metric as ConfigMetric
from metric_config_parser.metric import Summary as ConfigSummary
from metric_config_parser.pre_treatment import PreTreatmentReference
from metric_config_parser.statistic import Statistic as ConfigStatistic

from jetstream.statistics import Summary

summary_config = ConfigSummary(
metric=ConfigMetric(
name="dau_per_1000_clients", data_source=None, select_expression="1"
),
statistic=ConfigStatistic(name="bootstrap_mean", params={}),
pre_treatments=[PreTreatmentReference(name="normalize_over_analysis_period", args={})],
)

summary = Summary.from_config(summary_config, 7, AnalysisPeriod.WEEK)

(pre_treatment,) = summary.pre_treatments
assert pre_treatment.analysis_period_length == 7

# the pre-treatment actually scales values by the period length (7-day week)
df = pd.DataFrame({"dau_per_1000_clients": [1400.0, 7000.0]})
out = pre_treatment.apply(df, "dau_per_1000_clients")
assert list(out["dau_per_1000_clients"]) == [200.0, 1000.0]

def test_bootstrap_means(self):
stat = BootstrapMean(num_samples=10)
test_data = pd.DataFrame(
Expand Down
Loading