Skip to content

Commit 776e644

Browse files
committed
add robust ci to str
1 parent 20a4d6d commit 776e644

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

doubleml/irm/iivm.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ def __init__(
197197
self.subgroups = subgroups
198198
self._external_predictions_implemented = True
199199

200+
def __str__(self):
201+
parent_str = super().__str__()
202+
203+
# add robust confset
204+
if self.framework is None:
205+
confset_str = ""
206+
else:
207+
confset = self.robust_confset()
208+
formatted_confset = ", ".join([f"[{lower:.4f}, {upper:.4f}]" for lower, upper in confset])
209+
confset_str = (
210+
"\n\n--------------- Additional Information ----------------\n"
211+
+ f"Robust Confidence Set: {formatted_confset}\n"
212+
)
213+
214+
res = parent_str + confset_str
215+
return res
216+
200217
@property
201218
def normalize_ipw(self):
202219
"""

doubleml/irm/tests/test_iivm_unif_confset.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ def test_exceptions_robust_confset():
7676
with pytest.raises(ValueError, match=msg):
7777
dml_iivm_obj.robust_confset()
7878

79+
# Check if str representation of the object is working
80+
str_repr = str(dml_iivm_obj)
81+
assert isinstance(str_repr, str)
82+
assert "Robust" not in str_repr
83+
7984
# Fit the model
8085
dml_iivm_obj.fit()
8186

@@ -86,3 +91,8 @@ def test_exceptions_robust_confset():
8691
msg = r"The confidence level must be in \(0,1\). 1.5 was passed."
8792
with pytest.raises(ValueError, match=msg):
8893
dml_iivm_obj.robust_confset(level=1.5)
94+
95+
# Check if str representation of the object is working
96+
str_repr = str(dml_iivm_obj)
97+
assert isinstance(str_repr, str)
98+
assert "Robust Confidence Set" in str_repr

0 commit comments

Comments
 (0)