Open
Description
Bug Report
Description
My intuition regarding projection and aggregation is that they return objects that will behave the same as tables. For an ordinary table, bool(Table) == len(Table) > 0
, but this isn't the case for aggregations
Reproducibility
Include:
- OS Linux
- Python Version: 3.10
- MySQL Version: 8 latest
- MySQL Deployment Strategy local-docker
- DataJoint Version: 0.14.3
- Minimum number of steps to reliably reproduce the issue: see below
- Complete error stack as a result of evaluating the above steps: n/a
MWE
import datajoint as dj
schema = dj.schema("cbroz_temp")
@schema
class A(dj.Lookup):
definition = """
a_id: int
"""
contents = [[i] for i in range(1, 3)]
@schema
class B(dj.Lookup):
definition = """
-> A
b_id: int
"""
contents = [(i, j) for i in range(1, 2) for j in range(4, 8)]
if __name__ == "__main__":
has_entry = A & "a_id=1"
no_entry = A & "a_id=3"
print("Table with contents as bool: ", bool(has_entry)) # True
print("Table without contents as bool: ", bool(no_entry)) # False
aggr_has_entry = has_entry.aggr(B, b_id="COUNT(b_id)")
aggr_no_entry = no_entry.aggr(B, b_id="COUNT(b_id)")
print("Aggr table with contents as bool: ", bool(aggr_has_entry)) # True
print("Aggr table without contents as bool: ", bool(aggr_no_entry)) # True
Expected Behavior
I expected bool(Aggr) == len(Aggr) > 0
Screenshots
n/a
Additional Research and Context
- Checked existing issues
- Looked at git blame for the relevant code. PR Pre-release 0.13dev2 candidate #850 featured this commit, which chose to make the QueryExpression bool based on length and the Aggregation bool based on it being a valid selection - Is this related to evaluations during cascading delete?