Skip to content

Commit d05cbdd

Browse files
refactor: rename Diagram.preview() to counts()
Avoids confusion with QueryExpression.preview() which shows table contents. Diagram.counts() returns row counts per table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a1d8557 commit d05cbdd

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/datajoint/diagram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This module provides the Diagram class for constructing derived views of the
55
dependency graph. Diagram supports set operators (+, -, *) for selecting subsets
66
of tables, restriction propagation (cascade, restrict) for selecting subsets of
7-
data, and inspection (preview, prune) for viewing those selections.
7+
data, and inspection (counts, prune) for viewing those selections.
88
99
Mutation operations (delete, drop) live in Table, which uses Diagram internally
1010
for graph computation.
@@ -607,9 +607,9 @@ def _apply_propagation_rule(
607607

608608
self._restriction_attrs.setdefault(child_node, set()).update(child_attrs)
609609

610-
def preview(self):
610+
def counts(self):
611611
"""
612-
Show affected tables and row counts without modifying data.
612+
Return affected row counts per table without modifying data.
613613
614614
Returns
615615
-------

src/datajoint/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ def delete(
10141014
diagram = diagram.cascade(self, part_integrity=part_integrity)
10151015

10161016
if dry_run:
1017-
return diagram.preview()
1017+
return diagram.counts()
10181018

10191019
conn = self.connection
10201020
prompt = conn._config["safemode"] if prompt is None else prompt

tests/integration/test_erd.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def test_prune_after_restrict(schema_simp_pop):
110110
"""Prune after restrict removes tables with zero matching rows."""
111111
diag = dj.Diagram(schema_simp_pop, context=LOCALS_SIMPLE)
112112
restricted = diag.restrict(A & "id_a=0")
113-
counts = restricted.preview()
113+
counts = restricted.counts()
114114

115115
pruned = restricted.prune()
116-
pruned_counts = pruned.preview()
116+
pruned_counts = pruned.counts()
117117

118118
# Every table in pruned preview should have > 0 rows
119119
assert all(c > 0 for c in pruned_counts.values()), "pruned diagram should have no zero-count tables"
@@ -128,10 +128,10 @@ def test_prune_after_cascade(schema_simp_pop):
128128
"""Prune after cascade removes tables with zero matching rows."""
129129
diag = dj.Diagram(schema_simp_pop, context=LOCALS_SIMPLE)
130130
cascaded = diag.cascade(A & "id_a=0")
131-
counts = cascaded.preview()
131+
counts = cascaded.counts()
132132

133133
pruned = cascaded.prune()
134-
pruned_counts = pruned.preview()
134+
pruned_counts = pruned.counts()
135135

136136
assert all(c > 0 for c in pruned_counts.values())
137137

@@ -159,9 +159,9 @@ def test_prune_then_restrict(schema_simp_pop):
159159
further = pruned.restrict(A & "id_a=0")
160160

161161
# Should not raise; further restriction should narrow results
162-
counts = further.preview()
162+
counts = further.counts()
163163
assert all(c >= 0 for c in counts.values())
164164
# Tighter restriction should produce fewer or equal rows
165-
pruned_counts = pruned.preview()
165+
pruned_counts = pruned.counts()
166166
for table in counts:
167167
assert counts[table] <= pruned_counts.get(table, 0)

0 commit comments

Comments
 (0)