Skip to content

Commit fcf11c2

Browse files
committed
Fix tests
1 parent fe3a055 commit fcf11c2

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

econml/tests/test_dml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def test_can_custom_splitter(self):
699699
def test_can_use_featurizer(self):
700700
"Test that we can use a featurizer, and that fit is only called during training"
701701
dml = LinearDMLCateEstimator(LinearRegression(), LinearRegression(),
702-
fit_cate_intercept=False, featurizer=OneHotEncoder(n_values='auto', sparse=False))
702+
fit_cate_intercept=False, featurizer=OneHotEncoder(sparse=False))
703703

704704
T = np.tile([1, 2, 3], 6)
705705
Y = np.array([1, 2, 3, 1, 2, 3])

econml/tests/test_drlearner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def test_sparse(self):
713713
y_lower, y_upper = sparse_dml.effect_interval(x_test, T0=0, T1=1)
714714
in_CI = ((y_lower < true_eff) & (true_eff < y_upper))
715715
# Check that a majority of true effects lie in the 5-95% CI
716-
self.assertTrue(in_CI.mean() > 0.8)
716+
self.assertGreater(in_CI.mean(), 0.8)
717717

718718
def _test_te(self, learner_instance, tol, te_type="const"):
719719
if te_type not in ["const", "heterogeneous"]:

econml/tests/test_orf.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ def test_effect_shape(self):
184184

185185
def test_nuisance_model_has_weights(self):
186186
"""Test whether the correct exception is being raised if model_final doesn't have weights."""
187+
188+
# Create a wrapper around Lasso that doesn't support weights
189+
# since Lasso does natively support them starting in sklearn 0.23
190+
class NoWeightModel:
191+
def __init__(self):
192+
self.model = Lasso()
193+
194+
def fit(self, X, y):
195+
self.model.fit(X, y)
196+
return self
197+
198+
def predict(self, X):
199+
return self.model.predict(X)
200+
187201
# Generate data with continuous treatments
188202
T = np.dot(TestOrthoForest.W[:, TestOrthoForest.support], TestOrthoForest.coefs_T) + \
189203
TestOrthoForest.eta_sample(TestOrthoForest.n)
@@ -192,14 +206,14 @@ def test_nuisance_model_has_weights(self):
192206
T * TE + TestOrthoForest.epsilon_sample(TestOrthoForest.n)
193207
# Instantiate model with most of the default parameters
194208
est = ContinuousTreatmentOrthoForest(n_jobs=4, n_trees=10,
195-
model_T=Lasso(),
196-
model_Y=Lasso())
209+
model_T=NoWeightModel(),
210+
model_Y=NoWeightModel())
197211
est.fit(Y=Y, T=T, X=TestOrthoForest.X, W=TestOrthoForest.W)
198212
weights_error_msg = (
199213
"Estimators of type {} do not accept weights. "
200214
"Consider using the class WeightedModelWrapper from econml.utilities to build a weighted model."
201215
)
202-
self.assertRaisesRegexp(TypeError, weights_error_msg.format("Lasso"),
216+
self.assertRaisesRegexp(TypeError, weights_error_msg.format("NoWeightModel"),
203217
est.effect, X=TestOrthoForest.X)
204218

205219
def _test_te(self, learner_instance, expected_te, tol, treatment_type='continuous'):

0 commit comments

Comments
 (0)