Skip to content

Commit 44215e7

Browse files
committed
Update Test.
1 parent f7fea25 commit 44215e7

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed

datajoint/expression.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,11 @@ def tail(self, limit=25, **fetch_kwargs):
439439

440440
def __len__(self):
441441
""":return: number of elements in the result set e.g. ``len(q1)``."""
442-
try:
443-
if self._left[0]:
444-
return self.connection.query(
445-
'SELECT distinct count(*) FROM {from_}{where}'.format(
446-
from_=self.from_clause(),
447-
where=self.where_clause())).fetchone()[0]
448-
except IndexError:
449-
pass
450442
return self.connection.query(
451-
'SELECT count(DISTINCT {fields}) FROM {from_}{where}'.format(
452-
fields=self.heading.as_sql(self.primary_key, include_aliases=False),
443+
'SELECT {select_} FROM {from_}{where}'.format(
444+
select_=('DISTINCT count(*)' if any(self._left)
445+
else 'count(DISTINCT {fields})'.format(fields=self.heading.as_sql(
446+
self.primary_key, include_aliases=False))),
453447
from_=self.from_clause(),
454448
where=self.where_clause())).fetchone()[0]
455449

tests/test_aggr_regressions.py

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from . import PREFIX, CONN_INFO
99
import datetime
1010
import numpy as np
11+
import uuid
12+
from .schema_uuid import Topic, Item, top_level_namespace_id
1113
schema = dj.Schema(PREFIX + '_aggr_regress', connection=dj.conn(**CONN_INFO))
1214

1315
# --------------- ISSUE 386 -------------------
@@ -95,38 +97,6 @@ class X(dj.Lookup):
9597
contents = zip(range(10))
9698

9799

98-
@schema
99-
class Parent(dj.Manual):
100-
definition = """
101-
# Parent table
102-
id: int
103-
---
104-
txt = "NA" : varchar(32)
105-
"""
106-
107-
108-
@schema
109-
class Child(dj.Computed):
110-
definition = """
111-
# Child table
112-
-> Parent
113-
start_time: datetime(6)
114-
---
115-
timestamps: longblob
116-
"""
117-
118-
def make(self, key):
119-
t = np.random.poisson(1000, 10)
120-
t.sort()
121-
self.insert1(
122-
{
123-
"start_time": datetime.datetime.now(),
124-
"timestamps": t,
125-
**key,
126-
}
127-
)
128-
print(f"ingested w/ {key}")
129-
130100
def test_issue558_part1():
131101
q = (A-B).proj(id2='3')
132102
assert_equal(len(A - B), len(q))
@@ -138,9 +108,11 @@ def test_issue558_part2():
138108

139109

140110
def test_left_join_len():
141-
Parent.insert1({"id": 1})
142-
Child.populate()
143-
Parent.insert([{"id": 2}, {"id": 3}, {"id": 4}])
144-
q = Parent.join(Child & "id != 1", left=True)
111+
Topic().add('jeff')
112+
Item.populate()
113+
Topic().add('jeff2')
114+
Topic().add('jeff3')
115+
q = Topic.join(Item - dict(topic_id=uuid.uuid5(top_level_namespace_id, 'jeff')),
116+
left=True)
145117
qf = q.fetch()
146118
assert len(q) == len(qf)

0 commit comments

Comments
 (0)