Skip to content

Commit 26f1b01

Browse files
committed
FIX(<PY3.5): ORDERED DiGRAPH for old Python to fix TCs
1 parent f9b2415 commit 26f1b01

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

graphkit/network.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"""
6666
import logging
6767
import os
68+
import sys
6869
import time
6970
from collections import defaultdict, namedtuple
7071
from io import StringIO
@@ -79,6 +80,31 @@
7980

8081
log = logging.getLogger(__name__)
8182

83+
84+
if sys.version_info < (3, 6):
85+
from collections import OrderedDict
86+
from .digraph import DiGraph
87+
88+
class OrderedDiGraph(DiGraph):
89+
"""
90+
Consistently ordered variant of :class:`~networkx.DiGraph`.
91+
92+
PY3.6 has inmsertion-order dicts, but PY3.5 has not.
93+
And behvavior *and TCs) in these environments may fail spuriously!
94+
Still *subgraphs* may not patch!
95+
96+
Fix from:
97+
https://networkx.github.io/documentation/latest/_modules/networkx/classes/ordered.html
98+
"""
99+
node_dict_factory = OrderedDict
100+
adjlist_outer_dict_factory = OrderedDict
101+
adjlist_inner_dict_factory = OrderedDict
102+
edge_attr_dict_factory = OrderedDict
103+
104+
# monkeypatch
105+
nx.DiGraph = OrderedDiGraph
106+
107+
82108
class DataPlaceholderNode(str):
83109
"""
84110
Dag node naming a data-value produced or required by an operation.

0 commit comments

Comments
 (0)