Skip to content

Commit 52f3eca

Browse files
committed
Simplify semantic incompatibility error message
The error message now simply indicates which attribute has no matching lineage without explaining the details of why (whether either operand has any lineage). Also applies black formatting fixes.
1 parent a15a396 commit 52f3eca

File tree

4 files changed

+46
-62
lines changed

4 files changed

+46
-62
lines changed

datajoint/condition.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,28 +162,10 @@ def assert_join_compatibility(expr1, expr2):
162162
# Check if they are homologous (same lineage)
163163
# None lineages are never homologous (not even with each other)
164164
if lineage1 is None or lineage2 is None or lineage1 != lineage2:
165-
# Non-homologous namesakes - error
166-
if lineage1 is None and lineage2 is None:
167-
msg = (
168-
f"Cannot join: attribute '{attr}' has no lineage in both operands "
169-
f"(native secondary attributes). Use .proj() to rename one."
170-
)
171-
elif lineage1 is None:
172-
msg = (
173-
f"Cannot join: attribute '{attr}' has lineage '{lineage2}' in one operand "
174-
f"but no lineage in the other. Use .proj() to rename one."
175-
)
176-
elif lineage2 is None:
177-
msg = (
178-
f"Cannot join: attribute '{attr}' has lineage '{lineage1}' in one operand "
179-
f"but no lineage in the other. Use .proj() to rename one."
180-
)
181-
else:
182-
msg = (
183-
f"Cannot join: attribute '{attr}' has different lineages "
184-
f"('{lineage1}' vs '{lineage2}'). Use .proj() to rename one."
185-
)
186-
raise DataJointError(msg)
165+
raise DataJointError(
166+
f"Ambiguous attribute '{attr}' has no matching lineage. "
167+
f"Use .proj() to rename it in one of the operands."
168+
)
187169

188170

189171
def make_condition(query_expression, condition, columns):

datajoint/expression.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ def join(self, other, semantic_check=True, left=False):
323323
join_attributes = get_homologous_namesakes(self, other)
324324
else:
325325
# Permissive mode: join on all namesakes regardless of lineage
326-
join_attributes = set(n for n in self.heading.names if n in other.heading.names)
326+
join_attributes = set(
327+
n for n in self.heading.names if n in other.heading.names
328+
)
327329
# needs subquery if self's FROM clause has common attributes with other's FROM clause
328330
need_subquery1 = need_subquery2 = bool(
329331
(set(self.original_heading.names) & set(other.original_heading.names))

datajoint/heading.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,30 @@
1717

1818
logger = logging.getLogger(__name__.split(".")[0])
1919

20-
default_attribute_properties = (
21-
dict( # these default values are set in computed attributes
22-
name=None,
23-
type="expression",
24-
in_key=False,
25-
nullable=False,
26-
default=None,
27-
comment="calculated attribute",
28-
autoincrement=False,
29-
numeric=None,
30-
string=None,
31-
uuid=False,
32-
json=None,
33-
is_blob=False,
34-
is_attachment=False,
35-
is_filepath=False,
36-
is_external=False,
37-
is_hidden=False,
38-
adapter=None,
39-
store=None,
40-
unsupported=False,
41-
attribute_expression=None,
42-
database=None,
43-
dtype=object,
44-
lineage=None, # "schema.table.attribute" string tracing attribute origin, or None
45-
)
20+
default_attribute_properties = dict( # these default values are set in computed attributes
21+
name=None,
22+
type="expression",
23+
in_key=False,
24+
nullable=False,
25+
default=None,
26+
comment="calculated attribute",
27+
autoincrement=False,
28+
numeric=None,
29+
string=None,
30+
uuid=False,
31+
json=None,
32+
is_blob=False,
33+
is_attachment=False,
34+
is_filepath=False,
35+
is_external=False,
36+
is_hidden=False,
37+
adapter=None,
38+
store=None,
39+
unsupported=False,
40+
attribute_expression=None,
41+
database=None,
42+
dtype=object,
43+
lineage=None, # "schema.table.attribute" string tracing attribute origin, or None
4644
)
4745

4846

datajoint/lineage.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,10 @@ def get_table_lineage(self, table_name):
104104
:param table_name: name of the table (without schema)
105105
:return: dict mapping attribute_name -> lineage (or None)
106106
"""
107-
result = (self & dict(table_name=table_name)).fetch(
108-
"attribute_name", "lineage"
109-
)
107+
result = (self & dict(table_name=table_name)).fetch("attribute_name", "lineage")
110108
if len(result[0]) == 0:
111109
return {}
112-
return {
113-
attr: (lin if lin else None)
114-
for attr, lin in zip(result[0], result[1])
115-
}
110+
return {attr: (lin if lin else None) for attr, lin in zip(result[0], result[1])}
116111

117112
def delete_table_lineage(self, table_name):
118113
"""
@@ -172,10 +167,14 @@ def compute_lineage_from_dependencies(connection, schema, table_name, attribute_
172167
# Handle alias nodes (numeric string nodes in the graph)
173168
if parent.isdigit():
174169
# Find the actual parent by traversing through alias
175-
for grandparent, gprops in connection.dependencies.parents(parent).items():
170+
for grandparent, gprops in connection.dependencies.parents(
171+
parent
172+
).items():
176173
if not grandparent.isdigit():
177174
parent = grandparent
178-
parent_attr = gprops.get("attr_map", {}).get(attribute_name, parent_attr)
175+
parent_attr = gprops.get("attr_map", {}).get(
176+
attribute_name, parent_attr
177+
)
179178
break
180179
parent_schema, parent_table = parse_full_table_name(parent)
181180
return compute_lineage_from_dependencies(
@@ -304,13 +303,16 @@ def get_lineage_for_heading(connection, schema, table_name, heading):
304303
:return: dict mapping attribute_name -> lineage (or None)
305304
"""
306305
# Check if ~lineage table exists
307-
lineage_table_exists = connection.query(
308-
"""
306+
lineage_table_exists = (
307+
connection.query(
308+
"""
309309
SELECT COUNT(*) FROM information_schema.tables
310310
WHERE table_schema = %s AND table_name = '~lineage'
311311
""",
312-
args=(schema,),
313-
).fetchone()[0] > 0
312+
args=(schema,),
313+
).fetchone()[0]
314+
> 0
315+
)
314316

315317
if lineage_table_exists:
316318
# Load from ~lineage table

0 commit comments

Comments
 (0)