Skip to content

Commit e7371aa

Browse files
authored
Merge pull request #354 from CITCOM-project/f-allian/chore
Strip Unused Dependencies
2 parents d3dd4ab + aa74852 commit e7371aa

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

causal_testing/specification/variable.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from collections.abc import Callable
66
from typing import TypeVar
77

8-
import lhsmdu
98
from pandas import DataFrame
109
from scipy.stats._distn_infrastructure import rv_generic
1110

@@ -38,19 +37,6 @@ def __init__(self, name: str, datatype: T, distribution: rv_generic = None, hidd
3837
def __repr__(self):
3938
return f"{self.typestring()}: {self.name}::{self.datatype.__name__}"
4039

41-
def sample(self, n_samples: int) -> [T]:
42-
"""Generate a Latin Hypercube Sample of size n_samples according to the
43-
Variable's distribution.
44-
45-
:param int n_samples: The number of samples to generate.
46-
:return: A list of samples
47-
:rtype: List[T]
48-
49-
"""
50-
assert self.distribution is not None, "Sampling requires a distribution to be specified."
51-
lhs = lhsmdu.sample(1, n_samples).tolist()[0]
52-
return lhsmdu.inverseTransformSample(self.distribution, lhs).tolist()
53-
5440
def typestring(self) -> str:
5541
"""Return the type of the Variable, e.g. INPUT, or OUTPUT. Note that
5642
this is NOT the datatype (int, str, etc.).

causal_testing/testing/metamorphic_relation.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class ShouldCause(MetamorphicRelation):
3939

4040
def to_json_stub(
4141
self,
42-
skip: bool = True,
42+
skip: bool = False,
4343
estimate_type: str = "coefficient",
4444
effect_type: str = "direct",
4545
estimator: str = "LinearRegressionEstimator",
4646
) -> dict:
4747
"""
4848
Convert to a JSON frontend stub string for user customisation.
49-
:param skip: Whether to skip the test
49+
:param skip: Whether to skip the test (default False).
5050
:param effect_type: The type of causal effect to consider (total or direct)
5151
:param estimate_type: The estimate type to use when evaluating tests
5252
:param estimator: The name of the estimator class to use when evaluating the test
@@ -77,14 +77,14 @@ class ShouldNotCause(MetamorphicRelation):
7777

7878
def to_json_stub(
7979
self,
80-
skip: bool = True,
80+
skip: bool = False,
8181
estimate_type: str = "coefficient",
8282
effect_type: str = "direct",
8383
estimator: str = "LinearRegressionEstimator",
8484
) -> dict:
8585
"""
8686
Convert to a JSON frontend stub string for user customisation.
87-
:param skip: Whether to skip the test
87+
:param skip: Whether to skip the test (default False).
8888
:param effect_type: The type of causal effect to consider (total or direct)
8989
:param estimate_type: The estimate type to use when evaluating tests
9090
:param estimator: The name of the estimator class to use when evaluating the test
@@ -244,6 +244,10 @@ def generate_causal_tests(
244244
if len(list(causal_dag.predecessors(relation.base_test_case.outcome_variable))) > 0
245245
]
246246

247+
logger.warning("The skip parameter is hard-coded to False during test generation for better integration with the "
248+
"causal testing component (python -m causal_testing test ...)"
249+
"Please carefully review the generated tests and decide which to skip.")
250+
247251
logger.info(f"Generated {len(tests)} tests. Saving to {output_path}.")
248252
with open(output_path, "w", encoding="utf-8") as f:
249253
json.dump({"tests": tests}, f, indent=2)

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ requires-python = ">=3.10"
1515
license = { text = "MIT" }
1616
keywords = ["causal inference", "verification"]
1717
dependencies = [
18-
"fitter~=1.7",
1918
"lifelines~=0.29.0",
20-
"lhsmdu~=1.1",
2119
"networkx>=3.4,<3.5",
2220
"numpy~=1.26",
2321
"pandas>=2.1",

tests/specification_tests/test_variable.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ class TestVariable(unittest.TestCase):
1313
def setUp(self) -> None:
1414
pass
1515

16-
def test_sample_flakey(self):
17-
ip = Input("ip", float, norm)
18-
self.assertGreater(kstest(ip.sample(10), norm.cdf).pvalue, 0.95)
19-
2016
def test_typestring(self):
2117
class Var(Variable):
2218
pass

tests/testing_tests/test_metamorphic_relations.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_should_not_cause_json_stub(self):
6262
"name": "X1 _||_ Z",
6363
"formula": "Z ~ X1",
6464
"alpha": 0.05,
65-
"skip": True,
65+
"skip": False,
6666
},
6767
)
6868

@@ -86,7 +86,7 @@ def test_should_not_cause_logistic_json_stub(self):
8686
"name": "X1 _||_ Z",
8787
"formula": "Z ~ X1",
8888
"alpha": 0.05,
89-
"skip": True,
89+
"skip": False,
9090
},
9191
)
9292

@@ -107,7 +107,7 @@ def test_should_cause_json_stub(self):
107107
"formula": "Z ~ X1",
108108
"treatment_variable": "X1",
109109
"name": "X1 --> Z",
110-
"skip": True,
110+
"skip": False,
111111
},
112112
)
113113

@@ -120,7 +120,7 @@ def test_should_cause_logistic_json_stub(self):
120120
should_cause_mr = ShouldCause(BaseTestCase("X1", "Z"), adj_set)
121121
self.assertEqual(
122122
should_cause_mr.to_json_stub(
123-
effect_type="total", estimate_type="unit_odds_ratio", estimator="LogisticRegressionEstimator", skip=True
123+
effect_type="total", estimate_type="unit_odds_ratio", estimator="LogisticRegressionEstimator", skip=False
124124
),
125125
{
126126
"effect": "total",
@@ -130,7 +130,7 @@ def test_should_cause_logistic_json_stub(self):
130130
"formula": "Z ~ X1",
131131
"treatment_variable": "X1",
132132
"name": "X1 --> Z",
133-
"skip": True,
133+
"skip": False,
134134
},
135135
)
136136

@@ -263,7 +263,7 @@ def test_generate_causal_tests_ignore_cycles(self):
263263
tests = json.load(f)
264264
expected = list(
265265
map(
266-
lambda x: x.to_json_stub(skip=True),
266+
lambda x: x.to_json_stub(skip=False),
267267
filter(
268268
lambda relation: len(list(dcg.predecessors(relation.base_test_case.outcome_variable))) > 0,
269269
relations,
@@ -282,7 +282,7 @@ def test_generate_causal_tests(self):
282282
tests = json.load(f)
283283
expected = list(
284284
map(
285-
lambda x: x.to_json_stub(skip=True),
285+
lambda x: x.to_json_stub(skip=False),
286286
filter(
287287
lambda relation: len(list(dag.predecessors(relation.base_test_case.outcome_variable))) > 0,
288288
relations,

0 commit comments

Comments
 (0)