Skip to content

Commit 87451c4

Browse files
Merge pull request #966 from jverswijver/left_join_len_bug
Fix __len__() for left join QueryExpressions
2 parents a1d27f3 + 15146b1 commit 87451c4

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Bugfix - Replace use of numpy aliases of built-in types with built-in type. (#938) PR #939
77
* Bugfix - `ExternalTable.delete` should not remove row on error (#953) PR #956
88
* Bugfix - Fix error handling of remove_object function in `s3.py` (#952) PR #955
9+
* Bugfix - Fix count for left-joined `QueryExpressions` (#951) PR #966
910
* Bugfix - Fix assertion error when performing a union into a join (#930) PR #967
1011

1112
### 0.13.2 -- May 7, 2021

datajoint/expression.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ def tail(self, limit=25, **fetch_kwargs):
442442
def __len__(self):
443443
""":return: number of elements in the result set e.g. ``len(q1)``."""
444444
return self.connection.query(
445-
'SELECT count(DISTINCT {fields}) FROM {from_}{where}'.format(
446-
fields=self.heading.as_sql(self.primary_key, include_aliases=False),
445+
'SELECT {select_} FROM {from_}{where}'.format(
446+
select_=('count(*)' if any(self._left)
447+
else 'count(DISTINCT {fields})'.format(fields=self.heading.as_sql(
448+
self.primary_key, include_aliases=False))),
447449
from_=self.from_clause(),
448450
where=self.where_clause())).fetchone()[0]
449451

docs-parts/intro/Releases_lang1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Bugfix - Replace use of numpy aliases of built-in types with built-in type. (#938) PR #939
66
* Bugfix - `ExternalTable.delete` should not remove row on error (#953) PR #956
77
* Bugfix - Fix error handling of remove_object function in `s3.py` (#952) PR #955
8+
* Bugfix - Fix count for left-joined ``QueryExpressions`` (#951) PR #966
89
* Bugfix - Fix assertion error when performing a union into a join (#930) PR #967
910

1011
0.13.2 -- May 7, 2021

tests/test_aggr_regressions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from nose.tools import assert_equal, raises
77
import datajoint as dj
88
from . import PREFIX, CONN_INFO
9-
9+
import uuid
10+
from .schema_uuid import Topic, Item, top_level_namespace_id
1011
schema = dj.Schema(PREFIX + '_aggr_regress', connection=dj.conn(**CONN_INFO))
1112

1213
# --------------- ISSUE 386 -------------------
@@ -104,6 +105,17 @@ def test_issue558_part2():
104105
assert_equal(len(X & d), len((X & d).proj(id2='3')))
105106

106107

108+
def test_left_join_len():
109+
Topic().add('jeff')
110+
Item.populate()
111+
Topic().add('jeff2')
112+
Topic().add('jeff3')
113+
q = Topic.join(Item - dict(topic_id=uuid.uuid5(top_level_namespace_id, 'jeff')),
114+
left=True)
115+
qf = q.fetch()
116+
assert len(q) == len(qf)
117+
118+
107119
def test_union_join():
108120
# https://github.com/datajoint/datajoint-python/issues/930
109121
A.insert(zip([100, 200, 300, 400, 500, 600]))

tests/test_s3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_remove_object_exception():
7070

7171
# Apply our new minio client which has a user that does not exist
7272
schema.external['share'].s3.client = Minio(
73-
'minio:9000',
73+
S3_CONN_INFO['endpoint'],
7474
access_key='jeffjeff',
7575
secret_key='jeffjeff',
7676
secure=False)

0 commit comments

Comments
 (0)