Skip to content

Commit edd4779

Browse files
fix several diagramming issues
1 parent 4c8dd3d commit edd4779

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

datajoint/dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def load(self):
6262
# add edges to the graph
6363
for fk in fks.values():
6464
props = dict(
65-
primary=all(attr in pks[fk['referencing_table']] for attr in fk['attr_map']),
65+
primary=set(fk['attr_map']) <= set(pks[fk['referencing_table']]),
6666
attr_map=fk['attr_map'],
6767
aliased=any(k != v for k, v in fk['attr_map'].items()),
68-
multi=not all(a in fk['attr_map'] for a in pks[fk['referencing_table']]))
68+
multi=set(fk['attr_map']) != set(pks[fk['referencing_table']]))
6969
if not props['aliased']:
7070
self.add_edge(fk['referenced_table'], fk['referencing_table'], **props)
7171
else:

datajoint/diagram.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def __add__(self, arg):
191191
new = nx.algorithms.boundary.node_boundary(self, self.nodes_to_show)
192192
if not new:
193193
break
194+
# add nodes referenced by aliased nodes
195+
new.update(nx.algorithms.boundary.node_boundary(self, (a for a in new if a.isdigit())))
194196
self.nodes_to_show.update(new)
195197
return self
196198

@@ -207,9 +209,12 @@ def __sub__(self, arg):
207209
self.nodes_to_show.remove(arg.full_table_name)
208210
except AttributeError:
209211
for i in range(arg):
210-
new = nx.algorithms.boundary.node_boundary(nx.DiGraph(self).reverse(), self.nodes_to_show)
212+
graph = nx.DiGraph(self).reverse()
213+
new = nx.algorithms.boundary.node_boundary(graph, self.nodes_to_show)
211214
if not new:
212215
break
216+
# add nodes referenced by aliased nodes
217+
new.update(nx.algorithms.boundary.node_boundary(graph, (a for a in new if a.isdigit())))
213218
self.nodes_to_show.update(new)
214219
return self
215220

@@ -229,8 +234,10 @@ def _make_graph(self):
229234
"""
230235
# mark "distinguished" tables, i.e. those that introduce new primary key attributes
231236
for name in self.nodes_to_show:
232-
foreign_attributes = set(attr for p in self.in_edges(name, data=True) for attr in p[2]['attr_map'])
233-
self.node[name]['distinguished'] = foreign_attributes < self.node[name]['primary_key']
237+
foreign_attributes = set(
238+
attr for p in self.in_edges(name, data=True) for attr in p[2]['attr_map'] if p[2]['primary'])
239+
self.node[name]['distinguished'] = (
240+
'primary_key' in self.node[name] and foreign_attributes < self.node[name]['primary_key'])
234241
# include aliased nodes that are sandwiched between two displayed nodes
235242
gaps = set(nx.algorithms.boundary.node_boundary(self, self.nodes_to_show)).intersection(
236243
nx.algorithms.boundary.node_boundary(nx.DiGraph(self).reverse(), self.nodes_to_show))

datajoint/fetch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def __call__(self, *attrs, offset=None, limit=None, order_by=None, format=None,
121121
:param download_path: for fetches that download data, e.g. attachments
122122
:return: the contents of the relation in the form of a structured numpy.array or a dict list
123123
"""
124-
125124
if order_by is not None:
126125
# if 'order_by' passed in a string, make into list
127126
if isinstance(order_by, str):

tests/test_erd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_erd():
4343
def test_erd_algebra():
4444
erd0 = dj.ERD(B)
4545
erd1 = erd0 + 3
46-
erd2 = dj.ERD(E) - 3
46+
erd2 = dj.Di(E) - 3
4747
erd3 = erd1 * erd2
4848
erd4 = (erd0 + E).add_parts() - B - E
4949
assert_true(erd0.nodes_to_show == set(cls.full_table_name for cls in [B]))

0 commit comments

Comments
 (0)