Skip to content

Commit 384f026

Browse files
fix: clean up after cascade classmethod refactor
- Remove dead _source attribute (set but never read) - Update counts() error message to reference Diagram.cascade() - Update restrict() error message and docstring Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 923e01f commit 384f026

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/datajoint/diagram.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def __init__(self, source, context=None) -> None:
100100
self._restrict_conditions = copy_module.deepcopy(source._restrict_conditions)
101101
self._restriction_attrs = copy_module.deepcopy(source._restriction_attrs)
102102
self._part_integrity = source._part_integrity
103-
self._source = getattr(source, "_source", None)
104103
super().__init__(source)
105104
return
106105

@@ -132,7 +131,6 @@ def __init__(self, source, context=None) -> None:
132131

133132
# Enumerate nodes from all the items in the list
134133
self.nodes_to_show = set()
135-
self._source = None
136134
try:
137135
self.nodes_to_show.add(source.full_table_name)
138136
except AttributeError:
@@ -360,8 +358,6 @@ def cascade(cls, table_expr, part_integrity="enforce"):
360358
result._restrict_conditions = {}
361359
result._restriction_attrs = {}
362360
result._part_integrity = part_integrity
363-
result._source = table_expr
364-
365361
# Include seed + all descendants
366362
descendants = set(nx.descendants(result, node)) | {node}
367363
result.nodes_to_show = descendants
@@ -417,7 +413,7 @@ def restrict(self, table_expr):
417413
AND at convergence — a child row is included only if it satisfies
418414
*all* restricted ancestors. Used for export. Can be chained.
419415
420-
Cannot be called on a cascade-restricted Diagram.
416+
Cannot be called on a Diagram produced by ``Diagram.cascade()``.
421417
422418
Parameters
423419
----------
@@ -431,8 +427,8 @@ def restrict(self, table_expr):
431427
"""
432428
if self._cascade_restrictions:
433429
raise DataJointError(
434-
"Cannot apply restrict() on a cascade-restricted Diagram. "
435-
"cascade and restrict modes are mutually exclusive."
430+
"Cannot apply restrict() on a Diagram produced by Diagram.cascade(). "
431+
"cascade and restrict are mutually exclusive modes."
436432
)
437433
result = Diagram(self)
438434
node = table_expr.full_table_name
@@ -611,7 +607,9 @@ def counts(self):
611607
"""
612608
restrictions = self._cascade_restrictions or self._restrict_conditions
613609
if not restrictions:
614-
raise DataJointError("No restrictions applied. " "Call cascade() or restrict() first.")
610+
raise DataJointError(
611+
"No restrictions applied. " "Use Diagram.cascade(table_expr) or diag.restrict(table_expr) first."
612+
)
615613

616614
result = {}
617615
for ft in self:

0 commit comments

Comments
 (0)