From e54a01a18c5c8a29190a3c5959ae7c3722c304bd Mon Sep 17 00:00:00 2001 From: f-allian Date: Mon, 11 Aug 2025 10:32:04 +0100 Subject: [PATCH 1/4] fix: remove unwanted dependenices --- causal_testing/specification/variable.py | 14 -------------- pyproject.toml | 2 -- tests/specification_tests/test_variable.py | 4 ---- 3 files changed, 20 deletions(-) diff --git a/causal_testing/specification/variable.py b/causal_testing/specification/variable.py index 47345443..3642ea83 100644 --- a/causal_testing/specification/variable.py +++ b/causal_testing/specification/variable.py @@ -5,7 +5,6 @@ from collections.abc import Callable from typing import TypeVar -import lhsmdu from pandas import DataFrame from scipy.stats._distn_infrastructure import rv_generic @@ -38,19 +37,6 @@ def __init__(self, name: str, datatype: T, distribution: rv_generic = None, hidd def __repr__(self): return f"{self.typestring()}: {self.name}::{self.datatype.__name__}" - def sample(self, n_samples: int) -> [T]: - """Generate a Latin Hypercube Sample of size n_samples according to the - Variable's distribution. - - :param int n_samples: The number of samples to generate. - :return: A list of samples - :rtype: List[T] - - """ - assert self.distribution is not None, "Sampling requires a distribution to be specified." - lhs = lhsmdu.sample(1, n_samples).tolist()[0] - return lhsmdu.inverseTransformSample(self.distribution, lhs).tolist() - def typestring(self) -> str: """Return the type of the Variable, e.g. INPUT, or OUTPUT. Note that this is NOT the datatype (int, str, etc.). diff --git a/pyproject.toml b/pyproject.toml index 5be7b7a5..1b8b1787 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,9 +15,7 @@ requires-python = ">=3.10" license = { text = "MIT" } keywords = ["causal inference", "verification"] dependencies = [ - "fitter~=1.7", "lifelines~=0.29.0", - "lhsmdu~=1.1", "networkx>=3.4,<3.5", "numpy~=1.26", "pandas>=2.1", diff --git a/tests/specification_tests/test_variable.py b/tests/specification_tests/test_variable.py index d7173f2c..eabcf833 100644 --- a/tests/specification_tests/test_variable.py +++ b/tests/specification_tests/test_variable.py @@ -13,10 +13,6 @@ class TestVariable(unittest.TestCase): def setUp(self) -> None: pass - def test_sample_flakey(self): - ip = Input("ip", float, norm) - self.assertGreater(kstest(ip.sample(10), norm.cdf).pvalue, 0.95) - def test_typestring(self): class Var(Variable): pass From 2a2686401a2d8a84280f7ef28fa85ca2f16ff8a6 Mon Sep 17 00:00:00 2001 From: f-allian Date: Mon, 11 Aug 2025 10:47:12 +0100 Subject: [PATCH 2/4] fix: skip parameter should default to False --- causal_testing/testing/metamorphic_relation.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/causal_testing/testing/metamorphic_relation.py b/causal_testing/testing/metamorphic_relation.py index 55b4381f..b3b44af5 100644 --- a/causal_testing/testing/metamorphic_relation.py +++ b/causal_testing/testing/metamorphic_relation.py @@ -39,14 +39,14 @@ class ShouldCause(MetamorphicRelation): def to_json_stub( self, - skip: bool = True, + skip: bool = False, estimate_type: str = "coefficient", effect_type: str = "direct", estimator: str = "LinearRegressionEstimator", ) -> dict: """ Convert to a JSON frontend stub string for user customisation. - :param skip: Whether to skip the test + :param skip: Whether to skip the test (default False). :param effect_type: The type of causal effect to consider (total or direct) :param estimate_type: The estimate type to use when evaluating tests :param estimator: The name of the estimator class to use when evaluating the test @@ -77,14 +77,14 @@ class ShouldNotCause(MetamorphicRelation): def to_json_stub( self, - skip: bool = True, + skip: bool = False, estimate_type: str = "coefficient", effect_type: str = "direct", estimator: str = "LinearRegressionEstimator", ) -> dict: """ Convert to a JSON frontend stub string for user customisation. - :param skip: Whether to skip the test + :param skip: Whether to skip the test (default False). :param effect_type: The type of causal effect to consider (total or direct) :param estimate_type: The estimate type to use when evaluating tests :param estimator: The name of the estimator class to use when evaluating the test @@ -244,6 +244,10 @@ def generate_causal_tests( if len(list(causal_dag.graph.predecessors(relation.base_test_case.outcome_variable))) > 0 ] + logger.warning("The skip parameter is hard-coded to False during test generation for better integration with the " + "causal testing component (python -m causal_testing test ...)" + "Please carefully review the generated tests and decide which to skip.") + logger.info(f"Generated {len(tests)} tests. Saving to {output_path}.") with open(output_path, "w", encoding="utf-8") as f: json.dump({"tests": tests}, f, indent=2) From 38a1fa4342fb4eae3b6f924dba587be8a904e07c Mon Sep 17 00:00:00 2001 From: f-allian Date: Mon, 11 Aug 2025 11:27:59 +0100 Subject: [PATCH 3/4] fix: pytest --- tests/testing_tests/test_metamorphic_relations.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testing_tests/test_metamorphic_relations.py b/tests/testing_tests/test_metamorphic_relations.py index 6d838126..b9bad6af 100644 --- a/tests/testing_tests/test_metamorphic_relations.py +++ b/tests/testing_tests/test_metamorphic_relations.py @@ -62,7 +62,7 @@ def test_should_not_cause_json_stub(self): "name": "X1 _||_ Z", "formula": "Z ~ X1", "alpha": 0.05, - "skip": True, + "skip": False, }, ) @@ -86,7 +86,7 @@ def test_should_not_cause_logistic_json_stub(self): "name": "X1 _||_ Z", "formula": "Z ~ X1", "alpha": 0.05, - "skip": True, + "skip": False, }, ) @@ -107,7 +107,7 @@ def test_should_cause_json_stub(self): "formula": "Z ~ X1", "treatment_variable": "X1", "name": "X1 --> Z", - "skip": True, + "skip": False, }, ) @@ -130,7 +130,7 @@ def test_should_cause_logistic_json_stub(self): "formula": "Z ~ X1", "treatment_variable": "X1", "name": "X1 --> Z", - "skip": True, + "skip": False, }, ) From 6563c609d332e90dc78dda75075d12fc2b5fe568 Mon Sep 17 00:00:00 2001 From: f-allian Date: Mon, 11 Aug 2025 11:35:15 +0100 Subject: [PATCH 4/4] fix: pytest again --- tests/testing_tests/test_metamorphic_relations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testing_tests/test_metamorphic_relations.py b/tests/testing_tests/test_metamorphic_relations.py index 785193a5..c8b25e71 100644 --- a/tests/testing_tests/test_metamorphic_relations.py +++ b/tests/testing_tests/test_metamorphic_relations.py @@ -120,7 +120,7 @@ def test_should_cause_logistic_json_stub(self): should_cause_mr = ShouldCause(BaseTestCase("X1", "Z"), adj_set) self.assertEqual( should_cause_mr.to_json_stub( - effect_type="total", estimate_type="unit_odds_ratio", estimator="LogisticRegressionEstimator", skip=True + effect_type="total", estimate_type="unit_odds_ratio", estimator="LogisticRegressionEstimator", skip=False ), { "effect": "total", @@ -263,7 +263,7 @@ def test_generate_causal_tests_ignore_cycles(self): tests = json.load(f) expected = list( map( - lambda x: x.to_json_stub(skip=True), + lambda x: x.to_json_stub(skip=False), filter( lambda relation: len(list(dcg.predecessors(relation.base_test_case.outcome_variable))) > 0, relations, @@ -282,7 +282,7 @@ def test_generate_causal_tests(self): tests = json.load(f) expected = list( map( - lambda x: x.to_json_stub(skip=True), + lambda x: x.to_json_stub(skip=False), filter( lambda relation: len(list(dag.predecessors(relation.base_test_case.outcome_variable))) > 0, relations,