Skip to content

Commit 2d9af37

Browse files
committed
Fix style and docs
Signed-off-by: Adam Li <[email protected]>
1 parent 8b1939b commit 2d9af37

File tree

8 files changed

+23
-31
lines changed

8 files changed

+23
-31
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
("py:obj", "nx.MixedEdgeGraph"),
314314
("py:obj", "networkx.MixedEdgeGraph"),
315315
("py:obj", "pywhy_graphs.networkx.MixedEdgeGraph"),
316+
("py:obj", "pywhy_nx.MixedEdgeGraph"),
316317
("py:class", "networkx.classes.mixededge.MixedEdgeGraph"),
317318
("py:class", "numpy._typing._array_like._SupportsArray"),
318319
("py:class", "numpy._typing._nested_sequence._NestedSequence"),

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Contents
2020

2121
installation
2222
api
23-
use
23+
Usage<use>
2424
whats_new
2525

2626
Team

docs/use.rst

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
:orphan:
2-
3-
Examples using pywhy-graphs
4-
===========================
1+
How to use pywhy-graphs with examples and tutorials
2+
===================================================
53

64
To be able to effectively use pywhy-graphs, look at some of the examples here
75
to learn everything you need! We give an overview of concepts in causal graphs.
86

9-
10-
.. toctree::
11-
:maxdepth: 1
12-
:hidden:
13-
14-
Examples<../auto_examples/index>
7+
.. include:: auto_examples/index.rst
8+
:start-after: :orphan:

examples/README.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
.. _examples_gallery:
2-
31
Examples Gallery
42
----------------
53

6-
Examples demonstrating how to use causal graphs.
4+
Simple examples demonstrating how to use causal graphs.

examples/intro/intro_causal_graphs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from scipy import stats
1818

1919
import pywhy_graphs
20+
import pywhy_graphs.networkx as pywhy_nx
2021
from pywhy_graphs import CPDAG, PAG
2122
from pywhy_graphs.viz import draw
2223

@@ -163,15 +164,15 @@ def clone(self):
163164

164165
# We can also look at m-separation statements similarly to a DAG.
165166
# For example, 'z' is still m-separated from 'x' because of the collider at 'y'
166-
print(f"'z' is d-separated from 'x': {nx.m_separated(admg, {'z'}, {'x'}, set())}")
167+
print(f"'z' is d-separated from 'x': {pywhy_nx.m_separated(admg, {'z'}, {'x'}, set())}")
167168

168169
# Conditioning on the collider, opens up the path
169-
print(f"'z' is d-separated from 'x' given 'y': {nx.m_separated(admg, {'z'}, {'x'}, {'y'})}")
170+
print(f"'z' is d-separated from 'x' given 'y': {pywhy_nx.m_separated(admg, {'z'}, {'x'}, {'y'})}")
170171

171172
# Say we add a bidirected edge between 'z' and 'x', then they are no longer
172173
# d-separated.
173174
admg.add_edge("z", "x", admg.bidirected_edge_name)
174-
print(f"'z' is d-separated from 'x': {nx.m_separated(admg, {'z'}, {'x'}, set())}")
175+
print(f"'z' is d-separated from 'x': {pywhy_nx.m_separated(admg, {'z'}, {'x'}, set())}")
175176

176177
# Markov Equivalence Classes
177178
# --------------------------

pywhy_graphs/algorithms/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def set_nodes_as_latent_confounders(G: Union[nx.DiGraph, ADMG], nodes: List[Node
106106
return new_graph
107107

108108

109-
def is_valid_mec_graph(G: Union[PAG, CPDAG], on_error: str = "raise") -> bool:
109+
def is_valid_mec_graph(G, on_error: str = "raise") -> bool:
110110
"""Check G is a valid PAG.
111111
112112
A valid CPDAG/PAG is one where each pair of nodes have
@@ -129,7 +129,7 @@ def is_valid_mec_graph(G: Union[PAG, CPDAG], on_error: str = "raise") -> bool:
129129
if isinstance(G, CPDAG):
130130
check_func = _check_adding_cpdag_edge
131131
elif isinstance(G, PAG):
132-
check_func = _check_adding_pag_edge
132+
check_func = _check_adding_pag_edge # type: ignore
133133

134134
for edge_type, edgeview in G.edges().items():
135135
for u, v in edgeview:

pywhy_graphs/array/export.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
from numpy.typing import ArrayLike
55

66
import pywhy_graphs
7-
import pywhy_graphs.networkx as pywhy_nx
87
from pywhy_graphs.classes.functions import edge_types
98
from pywhy_graphs.config import CLearnEndpoint, EdgeType
109
from pywhy_graphs.typing import Node
1110

1211

13-
def _graph_to_clearn_arr(G: pywhy_nx.MixedEdgeGraph) -> Tuple[ArrayLike, List[Node]]:
12+
def _graph_to_clearn_arr(G) -> Tuple[ArrayLike, List[Node]]:
1413
# define the array
1514
arr = np.zeros((G.number_of_nodes(), G.number_of_nodes()), dtype=int)
1615

@@ -125,9 +124,7 @@ def _graph_to_clearn_arr(G: pywhy_nx.MixedEdgeGraph) -> Tuple[ArrayLike, List[No
125124
return arr, arr_idx
126125

127126

128-
def clearn_arr_to_graph(
129-
arr: ArrayLike, arr_idx: List[Node], graph_type: str
130-
) -> pywhy_nx.MixedEdgeGraph:
127+
def clearn_arr_to_graph(arr: ArrayLike, arr_idx: List[Node], graph_type: str):
131128
"""Convert causal-learn array to a graph object.
132129
133130
Parameters
@@ -170,7 +167,7 @@ def clearn_arr_to_graph(
170167
elif graph_type == "admg":
171168
graph = pywhy_graphs.ADMG()
172169
elif graph_type == "cpdag":
173-
graph = pywhy_graphs.CPDAG()
170+
graph = pywhy_graphs.CPDAG() # type: ignore
174171
elif graph_type == "pag":
175172
graph = pywhy_graphs.PAG()
176173
else:
@@ -248,18 +245,21 @@ def clearn_arr_to_graph(
248245
elif (endpoint_v == CLearnEndpoint.TAIL) and (endpoint_u == CLearnEndpoint.TAIL):
249246
graph.add_edge(u, v, edge_type=graph.undirected_edge_name)
250247
else:
248+
if not hasattr(graph, "circle_edge_name"):
249+
raise RuntimeError(f"Graph {graph} is adding circular end points...")
250+
251251
# Endpoints contain a circle...
252252
# u o- v
253253
if endpoint_u == CLearnEndpoint.CIRCLE:
254-
graph.add_edge(v, u, edge_type=graph.circle_edge_name)
254+
graph.add_edge(v, u, edge_type=graph.circle_edge_name) # type: ignore
255255
elif endpoint_u == CLearnEndpoint.ARROW:
256256
graph.add_edge(v, u, edge_type=graph.directed_edge_name)
257257
elif endpoint_u == CLearnEndpoint.TAIL:
258258
graph.add_edge(v, u, edge_type=graph.undirected_edge_name)
259259

260260
# u -o v
261261
if endpoint_v == CLearnEndpoint.CIRCLE:
262-
graph.add_edge(u, v, edge_type=graph.circle_edge_name)
262+
graph.add_edge(u, v, edge_type=graph.circle_edge_name) # type: ignore
263263
elif endpoint_v == CLearnEndpoint.ARROW:
264264
graph.add_edge(u, v, edge_type=graph.directed_edge_name)
265265
elif endpoint_v == CLearnEndpoint.TAIL:
@@ -271,7 +271,7 @@ def clearn_arr_to_graph(
271271

272272

273273
def graph_to_arr(
274-
G: pywhy_nx.MixedEdgeGraph,
274+
G,
275275
format: str = "causal-learn",
276276
node_order: Optional[ArrayLike] = None,
277277
) -> Tuple[ArrayLike, List[Node]]:

pywhy_graphs/viz/draw.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from typing import Optional
22

3-
import pywhy_graphs.networkx as pywhy_nx
43

5-
6-
def draw(G: pywhy_nx.MixedEdgeGraph, direction: Optional[str] = None, pos: Optional[dict] = None):
4+
def draw(G, direction: Optional[str] = None, pos: Optional[dict] = None):
75
"""Visualize the graph.
86
97
Parameters

0 commit comments

Comments
 (0)