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
13 changes: 10 additions & 3 deletions econml/dowhy.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,16 @@ def __getattr__(self, attr):
# don't proxy special methods
if attr.startswith('__'):
raise AttributeError(attr)
elif attr in ['_cate_estimator', 'dowhy_',
'identified_estimand_', 'estimate_']:
return super().__getattr__(attr)
elif attr == "dowhy_":
if "dowhy_" not in dir(self):
raise AttributeError("Please call `DoWhyWrapper.fit` first before any other operations.")
else:
return self.dowhy_
elif attr in ['_cate_estimator', 'identified_estimand_', 'estimate_']:
if attr in dir(self):
return getattr(self, attr)
else:
raise AttributeError("call `DoWhyWrapper.fit` first before any other operations.")
elif attr.startswith('dowhy__'):
return getattr(self.dowhy_, attr[len('dowhy__'):])
elif hasattr(self.estimate_._estimator_object, attr):
Expand Down
9 changes: 9 additions & 0 deletions econml/tests/test_dowhy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ def test_store_dataframe_name(self):
np.testing.assert_array_equal(est._effect_modifiers, X_name)
np.testing.assert_array_equal(est._treatment, [T_name])
np.testing.assert_array_equal(est._outcome, [Y_name])

def test_dowhy_without_fit(self):
with self.assertRaises(AttributeError) as context:
LinearDRLearner().dowhy.refute_estimate(method_name="random_common_cause", num_simulations=3)
self.assertTrue("Please call `DoWhyWrapper.fit` first before any other operations." in str(context.exception))

with self.assertRaises(AttributeError) as context:
LinearDRLearner().dowhy._estimator_object
self.assertTrue("call `DoWhyWrapper.fit` first before any other operations." in str(context.exception))
Loading