Repository navigation
[Repo Assist] test(utils): add tests for regression and graph_operations utility modules - #1764
Open
github-actions[bot] wants to merge 3 commits into
Open
github-actions[bot] wants to merge 3 commits into
github-actions[bot] wants to merge 3 commits into
Conversation
The inner function poly_term captured the loop variable 'degree' by reference, so every function in the returned list evaluated to x^max_degree regardless of its index. Fix by binding each value via a default argument (_degree=degree). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Adds test coverage for two previously untested utility modules:
- tests/utils/test_regression.py
* get_numeric_features: numeric column detection, mixed types
* generate_moment_function: shape, constant g, linear g
* create_polynomial_function: regression tests for the loop-variable
closure bug (degree-0 returning x^max_degree instead of 1)
- tests/utils/test_graph_operations.py
* adjacency_matrix_to_adjacency_list: chain, labels, no edges
* find_ancestor: chain graph
* induced_graph: submatrix shape and content
* get_simple_ordered_tree / is_connected / convert_to_undirected_graph
* add_edge / del_edge: cycle guard and connectivity guard
* str_to_dot / daggity_to_dot: output format
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
75 tasks
emrekiciman
marked this pull request as ready for review
August 30, 2026 07:59
Contributor
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds unit tests for previously untested dowhy/utils modules and includes a small bug fix uncovered by the new regression tests.
Changes:
- Add new test suites for
regressionandgraph_operationsutility functions. - Fix a closure-capture bug in
create_polynomial_functionso each generated term uses the correct degree. - Validate key graph utility edge cases (cycle prevention, connectivity preservation, DAGGity conversion).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/utils/test_regression.py | Adds tests for numeric feature detection, moment function, and polynomial basis generation (incl. regression case for closure bug). |
| tests/utils/test_graph_operations.py | Adds tests for adjacency conversion, ancestor traversal, induced subgraphs, connectivity, edge edits, and DOT conversion helpers. |
| dowhy/utils/regression.py | Fixes polynomial term generation by binding loop variable via default argument. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import pytest |
| """Tests for dowhy/utils/graph_operations.py utility functions.""" | ||
|
|
||
| import numpy as np | ||
| import pytest |
| def test_column_order(self): | ||
| df = pd.DataFrame({"z": [1.0], "a": [2.0], "m": [3.0]}) | ||
| indices = get_numeric_features(df) | ||
| assert len(indices) == 3 |
62 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Adds test coverage for two previously untested utility modules in
dowhy/utils/:tests/utils/test_regression.pyget_numeric_features,generate_moment_function,create_polynomial_functiontests/utils/test_graph_operations.pyadjacency_matrix_to_adjacency_list,find_ancestor,induced_graph,get_simple_ordered_tree,is_connected,convert_to_undirected_graph,add_edge,del_edge,str_to_dot,daggity_to_dotKey highlights
Bug caught by new tests: closure bug in
create_polynomial_functionThe test
test_degree_zero_is_constant_one(andtest_each_function_computes_correct_power) expose a pre-existing closure bug where every function in the list returned bycreate_polynomial_function(n)computedx^ninstead ofx^0, x^1, ..., x^n. This PR includes the fix (a one-line default-argument binding).This bug silently corrupted the polynomial basis used by
NonParametricSensitivityAnalyzerincausal_refuters/reisz.py.graph_operationsedge-case coverageadd_edgecorrectly skips edges that would introduce a cycle.del_edgecorrectly restores edges that would disconnect the graph.Rationale
These utilities underpin core causal inference functionality (sensitivity analysis, graph operations) but had zero direct test coverage. The new tests are simple, fast, and require no heavy optional dependencies.
Test Status
✅
⚠️ Full test suite not runnable in this environment (no installed Python package env); test correctness was validated by manual execution of the logic.
flake8 . --count --select=E9,F63,F7,F82— no hard errors✅
black --check— no formatting changes needed✅
isort --check— import order unchanged