Skip to content

Commit 2116d5c

Browse files
[Repo Assist] fix(utils): capture loop variable in create_polynomial_function via default arg (#1763)
fix: capture loop variable in create_polynomial_function via default arg 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). Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 032dc17 commit 2116d5c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

dowhy/utils/regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def create_polynomial_function(max_degree):
4242
polynomial_function = []
4343
for degree in range(max_degree + 1):
4444

45-
def poly_term(x):
46-
return x[:, [0]] ** degree
45+
def poly_term(x, _degree=degree):
46+
return x[:, [0]] ** _degree
4747

4848
polynomial_function.append(poly_term)
4949
return polynomial_function

0 commit comments

Comments
 (0)