Skip to content

[Repo Assist] test(utils): add tests for regression and graph_operations utility modules - #1764

Open
github-actions[bot] wants to merge 3 commits into
mainfrom
repo-assist/test-utility-functions-8f9ed7a6ab90d723
Open

github-actions[bot] wants to merge 3 commits into
mainfrom
repo-assist/test-utility-functions-8f9ed7a6ab90d723

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Adds test coverage for two previously untested utility modules in dowhy/utils/:

File Functions covered
tests/utils/test_regression.py get_numeric_features, generate_moment_function, create_polynomial_function
tests/utils/test_graph_operations.py adjacency_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_dot

Key highlights

Bug caught by new tests: closure bug in create_polynomial_function

The test test_degree_zero_is_constant_one (and test_each_function_computes_correct_power) expose a pre-existing closure bug where every function in the list returned by create_polynomial_function(n) computed x^n instead of x^0, x^1, ..., x^n. This PR includes the fix (a one-line default-argument binding).

# Without fix: all functions return x^max_degree
fns = create_polynomial_function(4)
fns[0](x)  # returns x^4, not x^0 = 1 !

This bug silently corrupted the polynomial basis used by NonParametricSensitivityAnalyzer in causal_refuters/reisz.py.

graph_operations edge-case coverage

  • add_edge correctly skips edges that would introduce a cycle.
  • del_edge correctly restores edges that would disconnect the graph.
  • Ancestor traversal and induced-subgraph extraction are verified on small, known graphs.

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

✅ flake8 . --count --select=E9,F63,F7,F82 — no hard errors
✅ black --check — no formatting changes needed
✅ isort --check — import order unchanged
⚠️ Full test suite not runnable in this environment (no installed Python package env); test correctness was validated by manual execution of the logic.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

github-actions Bot and others added 2 commits August 20, 2026 13:46
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>
@emrekiciman
emrekiciman requested a lite review from Copilot August 30, 2026 07:59
@emrekiciman
emrekiciman marked this pull request as ready for review August 30, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 regression and graph_operations utility functions.
  • Fix a closure-capture bug in create_polynomial_function so 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants