Skip to content

Commit 87c6884

Browse files
fix #1057
1 parent 8985877 commit 87c6884

File tree

3 files changed

+6
-84
lines changed

3 files changed

+6
-84
lines changed

datajoint/dependencies.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@
55
from .errors import DataJointError
66

77

8-
def unite_master_parts(lst):
9-
"""
10-
re-order a list of table names so that part tables immediately follow their master tables without breaking
11-
the topological order.
12-
Without this correction, a simple topological sort may insert other descendants between master and parts.
13-
The input list must be topologically sorted.
14-
:example:
15-
unite_master_parts(
16-
['`s`.`a`', '`s`.`a__q`', '`s`.`b`', '`s`.`c`', '`s`.`c__q`', '`s`.`b__q`', '`s`.`d`', '`s`.`a__r`']) ->
17-
['`s`.`a`', '`s`.`a__q`', '`s`.`a__r`', '`s`.`b`', '`s`.`b__q`', '`s`.`c`', '`s`.`c__q`', '`s`.`d`']
18-
"""
19-
for i in range(2, len(lst)):
20-
name = lst[i]
21-
match = re.match(r"(?P<master>`\w+`.`#?\w+)__\w+`", name)
22-
if match: # name is a part table
23-
master = match.group("master")
24-
for j in range(i - 1, -1, -1):
25-
if lst[j] == master + "`" or lst[j].startswith(master + "__"):
26-
# move from the ith position to the (j+1)th position
27-
lst[j + 1 : i + 1] = [name] + lst[j + 1 : i]
28-
break
29-
return lst
30-
31-
328
class Dependencies(nx.DiGraph):
339
"""
3410
The graph of dependencies (foreign keys) between loaded tables.
@@ -168,9 +144,7 @@ def descendants(self, full_table_name):
168144
"""
169145
self.load(force=False)
170146
nodes = self.subgraph(nx.algorithms.dag.descendants(self, full_table_name))
171-
return unite_master_parts(
172-
[full_table_name] + list(nx.algorithms.dag.topological_sort(nodes))
173-
)
147+
return [full_table_name] + list(nx.algorithms.dag.topological_sort(nodes))
174148

175149
def ancestors(self, full_table_name):
176150
"""
@@ -181,8 +155,6 @@ def ancestors(self, full_table_name):
181155
nodes = self.subgraph(nx.algorithms.dag.ancestors(self, full_table_name))
182156
return list(
183157
reversed(
184-
unite_master_parts(
185-
list(nx.algorithms.dag.topological_sort(nodes)) + [full_table_name]
186-
)
158+
list(nx.algorithms.dag.topological_sort(nodes)) + [full_table_name]
187159
)
188160
)

datajoint/diagram.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66
import inspect
77
from .table import Table
8-
from .dependencies import unite_master_parts
98
from .user_tables import Manual, Imported, Computed, Lookup, Part
109
from .errors import DataJointError
1110
from .table import lookup_class_name
@@ -59,8 +58,7 @@ class Diagram:
5958
Entity relationship diagram, currently disabled due to the lack of required packages: matplotlib and pygraphviz.
6059
6160
To enable Diagram feature, please install both matplotlib and pygraphviz. For instructions on how to install
62-
these two packages, refer to http://docs.datajoint.io/setup/Install-and-connect.html#python and
63-
http://tutorials.datajoint.io/setting-up/datajoint-python.html
61+
these two packages, refer to https://datajoint.com/docs/core/datajoint-python/0.14/client/install/
6462
"""
6563

6664
def __init__(self, *args, **kwargs):
@@ -181,11 +179,9 @@ def is_part(part, master):
181179

182180
def topological_sort(self):
183181
""":return: list of nodes in topological order"""
184-
return unite_master_parts(
185-
list(
186-
nx.algorithms.dag.topological_sort(
187-
nx.DiGraph(self).subgraph(self.nodes_to_show)
188-
)
182+
return list(
183+
nx.algorithms.dag.topological_sort(
184+
nx.DiGraph(self).subgraph(self.nodes_to_show)
189185
)
190186
)
191187

tests/test_dependencies.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
11
from datajoint import errors
22
from pytest import raises
3-
from datajoint.dependencies import unite_master_parts
4-
5-
6-
def test_unite_master_parts():
7-
assert unite_master_parts(
8-
[
9-
"`s`.`a`",
10-
"`s`.`a__q`",
11-
"`s`.`b`",
12-
"`s`.`c`",
13-
"`s`.`c__q`",
14-
"`s`.`b__q`",
15-
"`s`.`d`",
16-
"`s`.`a__r`",
17-
]
18-
) == [
19-
"`s`.`a`",
20-
"`s`.`a__q`",
21-
"`s`.`a__r`",
22-
"`s`.`b`",
23-
"`s`.`b__q`",
24-
"`s`.`c`",
25-
"`s`.`c__q`",
26-
"`s`.`d`",
27-
]
28-
assert unite_master_parts(
29-
[
30-
"`lab`.`#equipment`",
31-
"`cells`.`cell_analysis_method`",
32-
"`cells`.`cell_analysis_method_task_type`",
33-
"`cells`.`cell_analysis_method_users`",
34-
"`cells`.`favorite_selection`",
35-
"`cells`.`cell_analysis_method__cell_selection_params`",
36-
"`lab`.`#equipment__config`",
37-
"`cells`.`cell_analysis_method__field_detect_params`",
38-
]
39-
) == [
40-
"`lab`.`#equipment`",
41-
"`lab`.`#equipment__config`",
42-
"`cells`.`cell_analysis_method`",
43-
"`cells`.`cell_analysis_method__cell_selection_params`",
44-
"`cells`.`cell_analysis_method__field_detect_params`",
45-
"`cells`.`cell_analysis_method_task_type`",
46-
"`cells`.`cell_analysis_method_users`",
47-
"`cells`.`favorite_selection`",
48-
]
493

504

515
def test_nullable_dependency(thing_tables):

0 commit comments

Comments
 (0)