Skip to content

Commit e6f27fe

Browse files
committed
fix: allow global and test-specific queries
1 parent 7965371 commit e6f27fe

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

causal_testing/main.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,24 @@ def create_causal_test(self, test: dict, base_test: BaseTestCase) -> CausalTestC
281281
if estimator_class is None:
282282
raise ValueError(f"Unknown estimator: {test['estimator']}")
283283

284-
# Filter the data if a test-specific query exists, otherwise use the original data
285-
test_query = test.get("query", self.query)
286-
287-
if test_query:
288-
logger.info(f"Applying test-specific query for '{test['name']}': {test_query}")
289-
filtered_df = self.data.query(test_query)
290-
else:
291-
filtered_df = self.data
284+
# Handle combined queries (global and test-specific)
285+
test_query = test.get("query")
286+
combined_query = None
287+
288+
if self.query and test_query:
289+
combined_query = f"({self.query}) and ({test_query})"
290+
logger.info(
291+
f"Combining global query '{self.query}' with test-specific query "
292+
f"'{test_query}' for test '{test['name']}'"
293+
)
294+
elif test_query:
295+
combined_query = test_query
296+
logger.info(f"Using test-specific query for '{test['name']}': {test_query}")
297+
elif self.query:
298+
combined_query = self.query
299+
logger.info(f"Using global query for '{test['name']}': {self.query}")
300+
301+
filtered_df = self.data.query(combined_query) if combined_query else self.data
292302

293303
# Create the estimator with correct parameters
294304
estimator = estimator_class(
@@ -300,7 +310,7 @@ def create_causal_test(self, test: dict, base_test: BaseTestCase) -> CausalTestC
300310
effect_modifiers=None,
301311
formula=test.get("formula"),
302312
alpha=test.get("alpha", 0.05),
303-
query=test_query,
313+
query=combined_query,
304314
)
305315

306316
# Get effect type and create expected effect

0 commit comments

Comments
 (0)