Skip to content

Fix d_separated deprecation warning #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions causallearn/utils/DAG2PAG.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
import networkx as nx
from networkx.algorithms import d_separated

from causallearn.graph.Dag import Dag
from causallearn.graph.Edge import Edge
Expand Down Expand Up @@ -66,7 +65,7 @@ def dag2pag(dag: Dag, islatent: List[Node], isselection: List[Node] = []) -> Gen
for Z in combinations(observed_nodes, l):
if nodex in Z or nodey in Z:
continue
if d_separated(dg, {nodes_ids[nodex]}, {nodes_ids[nodey]}, set(nodes_ids[z] for z in Z) | set([nodes_ids[s] for s in isselection])):
if nx.is_d_separator(dg, {nodes_ids[nodex]}, {nodes_ids[nodey]}, set(nodes_ids[z] for z in Z) | set([nodes_ids[s] for s in isselection])):
if edge:
PAG.remove_edge(edge)
sepset[(nodes_ids[nodex], nodes_ids[nodey])] |= set(Z)
Expand Down
2 changes: 1 addition & 1 deletion causallearn/utils/PCUtils/Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def draw_graph(nx_graph):
def is_dsep(nx_graph, x, y, Z):
"Return True if x and y are d-separated by the set Z in nx_graph (networkx graph object) and False otherwise"
S = set([str(i) for i in Z])
return nx.d_separated(nx_graph, {str(x)}, {str(y)}, S)
return nx.is_d_separator(nx_graph, {str(x)}, {str(y)}, S)


#######################################################################################################################
Expand Down
4 changes: 2 additions & 2 deletions causallearn/utils/cit.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ def __init__(self, data, true_dag=None, **kwargs):
def __call__(self, X, Y, condition_set=None):
Xs, Ys, condition_set, cache_key = self.get_formatted_XYZ_and_cachekey(X, Y, condition_set)
if cache_key in self.pvalue_cache: return self.pvalue_cache[cache_key]
p = float(nx.d_separated(self.true_dag, {Xs[0]}, {Ys[0]}, set(condition_set)))
# pvalue is bool here: 1 if is_d_separated and 0 otherwise. So heuristic comparison-based uc_rules will not work.
p = float(nx.is_d_separator(self.true_dag, {Xs[0]}, {Ys[0]}, set(condition_set)))
# pvalue is bool here: 1 if is_d_separator and 0 otherwise. So heuristic comparison-based uc_rules will not work.

# here we use networkx's d_separation implementation.
# an alternative is to use causal-learn's own d_separation implementation in graph class:
Expand Down