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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10","3.11","3.12"]
python-version: ["3.11","3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
20 changes: 12 additions & 8 deletions Murray/tests/test_power_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ def test_simulate_power(synthetic_series):
y_real = synthetic_series.copy()
y_control = synthetic_series.copy() * 0.95

delta, power, y_lifted, p_value = simulate_power(
delta, power, power_ci, y_lifted, p_value = simulate_power(
y_real=y_real,
y_control=y_control,
delta=0.1,
period=20,
n_permutations=100,
n_permutations_per_test=100,
significance_level=0.05,
n_power_simulations=10,
)

assert isinstance(delta, float), "Delta must be a float"
assert isinstance(power, float), "Statistical power must be a float"
assert isinstance(power_ci, tuple), "Power CI must be a tuple"
assert isinstance(y_lifted, np.ndarray), "The adjusted series must be a NumPy array"
assert isinstance(p_value, float), "P-value must be a float"
assert isinstance(p_value, (float, np.floating)), "P-value must be a float"
assert len(y_lifted) == len(
y_real
), "The adjusted series must have the same length as the original"
Expand All @@ -74,19 +76,21 @@ def test_run_simulation(synthetic_series):
y_real = synthetic_series.copy()
y_control = synthetic_series.copy() * 0.98

delta, power, y_lifted, p_value = run_simulation(
delta, power, power_ci, y_lifted, p_value = run_simulation(
delta=0.2,
y_real=y_real,
y_control=y_control,
period=20,
n_permutations=100,
n_permutations_per_test=100,
significance_level=0.05,
n_power_simulations=10,
)

assert isinstance(delta, float), "Delta must be a float"
assert isinstance(power, float), "Statistical power must be a float"
assert isinstance(power_ci, tuple), "Power CI must be a tuple"
assert isinstance(y_lifted, np.ndarray), "The adjusted series must be a NumPy array"
assert isinstance(p_value, float), "P-value must be a float"
assert isinstance(p_value, (float, np.floating)), "P-value must be a float"
assert 0 <= p_value <= 1, "P-value must be between 0 and 1"


Expand All @@ -100,14 +104,14 @@ def test_evaluate_sensitivity():
}
deltas = [0.05, 0.1, 0.2]
periods = [10, 20, 30]
n_permutations = 50

sensitivity_results, lift_series = evaluate_sensitivity(
results_by_size=results_by_size,
deltas=deltas,
periods=periods,
n_permutations=n_permutations,
n_permutations_per_test=50,
significance_level=0.05,
n_power_simulations=10,
)

assert isinstance(sensitivity_results, dict), "The result must be a dictionary"
Expand Down
24 changes: 16 additions & 8 deletions Murray/tests/test_run_geo_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def test_run_geo_analysis(sample_data):
deltas_range=(0.05, 0.2, 0.05),
periods_range=(10, 30, 10),
excluded_locations=["Location_1"],
n_permutations=100,
n_permutations_per_test=100,
n_power_simulations=10,
)

assert isinstance(results, dict), "The result must be a dictionary"
Expand Down Expand Up @@ -84,7 +85,8 @@ def test_run_geo_analysis_with_duplicates(sample_data_with_duplicates):
deltas_range=(0.05, 0.15, 0.05),
periods_range=(10, 20, 5),
excluded_locations=[],
n_permutations=50,
n_permutations_per_test=50,
n_power_simulations=10,
)

assert isinstance(results, dict), "The result must be a dictionary"
Expand All @@ -103,7 +105,8 @@ def test_run_geo_analysis_no_excluded_locations(sample_data):
deltas_range=(0.05, 0.10, 0.05),
periods_range=(10, 15, 5),
excluded_locations=[],
n_permutations=50,
n_permutations_per_test=50,
n_power_simulations=10,
)

assert isinstance(results, dict), "The result must be a dictionary"
Expand All @@ -121,7 +124,8 @@ def test_run_geo_analysis_high_treatment_percentage(sample_data):
deltas_range=(0.05, 0.10, 0.05),
periods_range=(10, 15, 5),
excluded_locations=[],
n_permutations=50,
n_permutations_per_test=50,
n_power_simulations=10,
)

assert isinstance(results, dict), "The result must be a dictionary"
Expand All @@ -137,7 +141,8 @@ def test_run_geo_analysis_low_significance_level(sample_data):
deltas_range=(0.05, 0.10, 0.05),
periods_range=(10, 15, 5),
excluded_locations=[],
n_permutations=50,
n_permutations_per_test=50,
n_power_simulations=10,
)

assert isinstance(results, dict), "The result must be a dictionary"
Expand All @@ -153,7 +158,8 @@ def test_run_geo_analysis_single_delta_period(sample_data):
deltas_range=(0.10, 0.11, 0.05),
periods_range=(15, 16, 5),
excluded_locations=[],
n_permutations=30,
n_permutations_per_test=30,
n_power_simulations=10,
)

assert isinstance(results, dict), "The result must be a dictionary"
Expand Down Expand Up @@ -219,7 +225,8 @@ def test_run_geo_analysis_insufficient_data():
deltas_range=(0.05, 0.10, 0.05),
periods_range=(5, 10, 5),
excluded_locations=[],
n_permutations=10,
n_permutations_per_test=10,
n_power_simulations=5,
)

assert isinstance(results, dict), "Should return dict even with insufficient data"
Expand All @@ -239,5 +246,6 @@ def test_run_geo_analysis_all_locations_excluded(sample_data):
deltas_range=(0.05, 0.10, 0.05),
periods_range=(10, 15, 5),
excluded_locations=all_locations,
n_permutations=30,
n_permutations_per_test=30,
n_power_simulations=10,
)
22 changes: 9 additions & 13 deletions Murray/tests/test_run_geo_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def test_run_geo_evaluation(sample_data):
"""Checks that the geographic evaluation function runs correctly"""
results = run_geo_evaluation(
data_input=sample_data,
start_treatment="2023-03-01",
end_treatment="2023-03-10",
start_treatment="01-03-2023", # dayfirst=True format: DD-MM-YYYY (March 1st)
end_treatment="10-03-2023", # March 10th
treatment_group=["Location_0", "Location_1"],
spend=50000,
n_permutations=100,
Expand All @@ -33,28 +33,24 @@ def test_run_geo_evaluation(sample_data):
)

assert isinstance(results, dict), "The result must be a dictionary"
expected_keys = [

# Check for essential keys (some keys might vary based on implementation)
essential_keys = [
"MAPE",
"SMAPE",
"counterfactual",
"treatment",
"p_value",
"power",
"percenge_lift",
"control_group",
"observed_stat",
"null_stats",
"weights",
"period",
"spend",
"length_treatment",
]
for key in expected_keys:
for key in essential_keys:
assert key in results, f"Missing the key '{key}' in the results"

assert isinstance(results["MAPE"], float), "MAPE must be a float"
assert isinstance(results["p_value"], float), "p_value must be a float"
assert isinstance(results["power"], float), "Power must be a float"
assert isinstance(results["MAPE"], (float, np.floating)), "MAPE must be a float"
assert isinstance(results["p_value"], (float, np.floating)), "p_value must be a float"
assert isinstance(results["power"], (float, np.floating)), "Power must be a float"
assert isinstance(results["control_group"], list), "Control group must be a list"
assert 0 <= results["power"] <= 1, "Power must be between 0 and 1"
assert 0 <= results["p_value"] <= 1, "p_value must be between 0 and 1"