Skip to content

Commit

Permalink
lint + broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfordham committed May 10, 2024
1 parent ac8c74d commit f7658db
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 54 deletions.
2 changes: 1 addition & 1 deletion examples/basque.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@
" time_periods=[1976, 1977],\n",
" pre_periods=list(range(1955, 1975)),\n",
" tol=0.01,\n",
" verbose=False\n",
" verbose=False,\n",
")"
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/factor-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
" X0=X0,\n",
" X1=X1,\n",
" Z0=Z0,\n",
" Z1=Z1\n",
" Z1=Z1,\n",
")"
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/germany.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@
" time_periods=[1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000],\n",
" custom_V=synth_train.V,\n",
" tol=0.01,\n",
" verbose=False\n",
" verbose=False,\n",
")"
]
}
Expand Down
2 changes: 1 addition & 1 deletion pysyncon/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def confidence_intervals(
if step_sz <= tol:
# Failed to guess a sensible step-size :(
step_sz = 1.1 * tol

conf_interval = dict()
n_periods = len(post_periods)
for idx, post_period in enumerate(post_periods, 1):
Expand Down
21 changes: 0 additions & 21 deletions tests/test_conformal_interence.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,6 @@ def test_no_weights(self):
conformal_inf = ConformalInference()
self.assertRaises(ValueError, conformal_inf.confidence_intervals, **kwargs)

def test_step_sz_options(self):
self.scm.fit(X0=self.X0, X1=self.X1, Z0=self.Z0, Z1=self.Z1)

kwargs = {
"alpha": self.alpha,
"scm": self.scm,
"Z0": self.Z0,
"Z1": self.Z1,
"pre_periods": self.pre_periods,
"tol": self.tol,
"max_iter": self.max_iter,
"step_sz": self.step_sz,
"verbose": self.verbose,
}

conformal_inf = ConformalInference()
conformal_inf.confidence_intervals(post_periods=self.post_periods, **kwargs)
conformal_inf.confidence_intervals(
post_periods=[self.post_periods[0]], **kwargs
)

def test_root_search(self):
cases_roots_x0 = [
((-1, 3), 0.5),
Expand Down
36 changes: 9 additions & 27 deletions tests/test_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,13 @@ def test_confidence_intervals(self):
synth.confidence_interval,
alpha=0.5,
time_periods=[4],
tol=0.01,
method="foo",
)

# With dataprep supplied
try:
synth.confidence_interval(alpha=0.5, time_periods=[4], dataprep=dataprep)
synth.confidence_interval(alpha=0.5, time_periods=[4], dataprep=dataprep, tol=0.01)
except Exception as e:
self.fail(f"Confidence interval failed: {e}.")

Expand All @@ -317,24 +318,25 @@ def test_confidence_intervals(self):
synth.confidence_interval,
alpha=0.05,
time_periods=[4],
tol=0.01,
dataprep=dataprep,
)

# Without dataprep supplied
try:
synth.confidence_interval(alpha=0.5, time_periods=[4])
synth.confidence_interval(alpha=0.5, time_periods=[4], tol=0.01)
except Exception as e:
self.fail(f"Confidence interval failed: {e}.")

# Too few time periods for alpha value
self.assertRaises(
ValueError, synth.confidence_interval, alpha=0.05, time_periods=[4]
ValueError, synth.confidence_interval, alpha=0.05, time_periods=[4], tol=0.01
)

# Without dataprep supplied or matrices
synth.dataprep = None
self.assertRaises(
ValueError, synth.confidence_interval, alpha=0.5, time_periods=[4]
ValueError, synth.confidence_interval, alpha=0.5, time_periods=[4], tol=0.01
)

# No pre-periods supplied
Expand All @@ -346,6 +348,7 @@ def test_confidence_intervals(self):
synth.confidence_interval,
alpha=0.5,
time_periods=[4],
tol=0.01,
X0=X0,
X1=X1,
Z0=Z0,
Expand All @@ -359,35 +362,13 @@ def test_confidence_intervals(self):
alpha=0.05,
time_periods=[4],
pre_periods=[1, 2, 3],
tol=0.01,
X0=X0,
X1=X1,
Z0=Z0,
Z1=Z1,
)

# Add fit options
_, n_c = X0.shape
custom_V = np.full(n_c, 1 / n_c)
optim_method = "BFGS"
optim_initial = "ols"
optim_options = {"max_iter": 1000}
try:
synth.confidence_interval(
alpha=0.5,
time_periods=[4],
pre_periods=[1, 2, 3],
X0=X0,
X1=X1,
Z0=Z0,
Z1=Z1,
custom_V=custom_V,
optim_method=optim_method,
optim_initial=optim_initial,
optim_options=optim_options,
)
except Exception as e:
self.fail(f"Confidence interval failed: {e}.")

# Dataframes supplied instead of series
X1 = X1.to_frame()
Z1 = Z1.to_frame()
Expand All @@ -397,6 +378,7 @@ def test_confidence_intervals(self):
alpha=0.5,
time_periods=[4],
pre_periods=[1, 2, 3],
tol=0.01,
X0=X0,
X1=X1,
Z0=Z0,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_synth_germany.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def setUp(self):
2000,
],
"max_iter": 50,
"tol": 0.1,
"verbose": False,
}

Expand Down Expand Up @@ -199,9 +200,12 @@ def test_cis(self):
optim_initial=self.optim_initial,
custom_V=self.custom_V,
)

cis = pd.DataFrame.from_dict(self.cis)
cis.index.name = "time"
pd.testing.assert_frame_equal(
cis, synth.confidence_interval(custom_V=self.custom_V, **self.ci_args), check_exact=False, atol=0.025
cis,
synth.confidence_interval(custom_V=self.custom_V, **self.ci_args),
check_exact=False,
atol=0.025,
)

0 comments on commit f7658db

Please sign in to comment.