From effc2afb507d7e8f88be04e9bec1451899a0d38a Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Mon, 17 Aug 2015 15:11:20 -0500 Subject: [PATCH 1/4] restored the init_command in Connection --- datajoint/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datajoint/connection.py b/datajoint/connection.py index 3c7559f94..ab00e3ab7 100644 --- a/datajoint/connection.py +++ b/datajoint/connection.py @@ -59,7 +59,7 @@ def __init__(self, host, user, passwd, init_fun=None): else: port = config['database.port'] self.conn_info = dict(host=host, port=port, user=user, passwd=passwd) - self._conn = connector.connect(**self.conn_info) + self._conn = connector.connect(init_command=init_fun, **self.conn_info) if self.is_connected: logger.info("Connected {user}@{host}:{port}".format(**self.conn_info)) else: From 16bd3c6ab56eceb4c12d20e11baaddba4d9e489d Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Mon, 17 Aug 2015 15:13:57 -0500 Subject: [PATCH 2/4] removed Join.counter as it was not used. --- datajoint/relational_operand.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/datajoint/relational_operand.py b/datajoint/relational_operand.py index 3ee608eba..7639d17bf 100644 --- a/datajoint/relational_operand.py +++ b/datajoint/relational_operand.py @@ -246,7 +246,6 @@ class Join(RelationalOperand): """ Relational join """ - __counter = 0 def __init__(self, arg1, arg2, left=False): if not isinstance(arg2, RelationalOperand): @@ -266,11 +265,6 @@ def _repr_helper(self): def connection(self): return self._arg1.connection - @property - def counter(self): - self.__counter += 1 - return self.__counter - @property def heading(self): return self._heading From 95b5abfaa3fb8536a404f6031c8fd660bc7dfd22 Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Tue, 18 Aug 2015 15:08:46 -0500 Subject: [PATCH 3/4] bugfix in restriction, extended tests for relational operators --- datajoint/relational_operand.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datajoint/relational_operand.py b/datajoint/relational_operand.py index 7639d17bf..9e98fd1e9 100644 --- a/datajoint/relational_operand.py +++ b/datajoint/relational_operand.py @@ -118,7 +118,9 @@ def __and__(self, restriction): ret = copy(self) ret._restrictions = list(ret.restrictions) # apply restrictions, if any - if isinstance(restriction, RelationalOperand) or restriction: + if isinstance(restriction, RelationalOperand) \ + or isinstance(restriction, np.void) \ + or restriction: restrictions = restriction \ if isinstance(restriction, list) or isinstance(restriction, tuple) \ else [restriction] From b5a0aced26122b507c21e7a18942d91bcc967de3 Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Tue, 18 Aug 2015 15:15:51 -0500 Subject: [PATCH 4/4] more tests of relational operators --- tests/test_relational_operand.py | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/test_relational_operand.py b/tests/test_relational_operand.py index 5b68bd529..f7851dc72 100644 --- a/tests/test_relational_operand.py +++ b/tests/test_relational_operand.py @@ -194,13 +194,15 @@ def test_join(): 'incorrect join primary_key') # test pairing - # Approach 1 - x = A().project(a1='id_a', c1='cond_in_a') & 'c1=0' - y = A().project(a2='id_a', c2='cond_in_a') & 'c2=1' + # Approach 1: join then restrict + x = A().project(a1='id_a', c1='cond_in_a') + y = A().project(a2='id_a', c2='cond_in_a') rel = x*y & 'c1=0' & 'c2=1' - assert_equal(len(x)+len(y), len(A())) - assert_equal(len(rel), len(x)*len(y), 'incorrect pairing') - # Approach 2 + assert_equal(len(x & 'c1=0')+len(y & 'c2=1'), len(A()), + 'incorrect restriction') + assert_equal(len(rel), len(x & 'c1=0')*len(y & 'c2=1'), + 'incorrect pairing') + # Approach 2: restrict then join x = (A() & 'cond_in_a=0').project(a1='id_a') y = (A() & 'cond_in_a=1').project(a2='id_a') assert_equal(len(rel), len(x*y)) @@ -208,12 +210,23 @@ def test_join(): @staticmethod def test_project(): x = A().project(a='id_a') # rename - assert_equal(x.heading.names, ['a'], 'renaming does not work') + assert_equal(x.heading.names, ['a'], + 'renaming does not work') x = A().project(a='(id_a)') # extend - assert_equal(set(x.heading.names), set(('id_a', 'a')), 'extend does not work') + assert_equal(set(x.heading.names), set(('id_a', 'a')), + 'extend does not work') @staticmethod def test_aggregate(): - x = B().aggregate(C(), 'n', computed='count(id_c)') + x = B().aggregate(C(), 'n', count='count(id_c)', mean='avg(value)', max='max(value)') assert_equal(len(x), len(B())) - + for n, count, mean, max, key in zip(*x.fetch['n', 'count', 'mean', 'max', dj.key]): + assert_equal(n, count, 'aggregation failed (count)') + values = (C() & key).fetch['value'] + assert_true(bool(len(values)) == bool(n), + 'aggregation failed (restriction)') + if n: + assert_true(np.isclose(mean, values.mean(), rtol=1e-4, atol=1e-5), + "aggregation failed (mean)") + assert_true(np.isclose(max, values.max(), rtol=1e-4, atol=1e-5), + "aggregation failed (max)")