Skip to content

Commit ed16dc8

Browse files
Incorporate feedback and add test for #898.
1 parent 0c98e86 commit ed16dc8

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

datajoint/diagram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def _make_graph(self):
219219
"""
220220
Make the self.graph - a graph object ready for drawing
221221
"""
222-
# mark "distinguished" tables i.e. ones introduce new primary key attributes
222+
# mark "distinguished" tables, i.e. those that introduce new primary key
223+
# attributes
223224
for name in self.nodes_to_show:
224225
foreign_attributes = set(
225226
attr for p in self.in_edges(name, data=True)

tests/test_relational_operand.py

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import datetime
55

66
import numpy as np
7-
from nose.tools import assert_equal, assert_false, assert_true, raises, assert_set_equal, assert_list_equal
7+
from nose.tools import (assert_equal, assert_false, assert_true, raises, assert_set_equal,
8+
assert_list_equal)
89

910
import datajoint as dj
1011
from .schema_simple import (A, B, D, E, F, L, DataA, DataB, TTestUpdate, IJ, JI,
@@ -159,6 +160,76 @@ def test_issue_376():
159160
def test_issue_463():
160161
assert_equal(((A & B) * B).fetch().size, len(A * B))
161162

163+
@staticmethod
164+
def test_issue_898():
165+
# https://github.com/datajoint/datajoint-python/issues/898
166+
schema = dj.schema('djtest_raphael')
167+
168+
@schema
169+
class Subject(dj.Lookup):
170+
definition = """
171+
subject_id: varchar(32)
172+
---
173+
dob : date
174+
sex : enum('M', 'F', 'U')
175+
"""
176+
contents = [
177+
('mouse1', '2020-09-01', 'M'),
178+
('mouse2', '2020-03-19', 'F'),
179+
('mouse3', '2020-08-23', 'F')
180+
]
181+
182+
@schema
183+
class Session(dj.Lookup):
184+
definition = """
185+
-> Subject
186+
session_start_time: datetime
187+
---
188+
session_dir='' : varchar(32)
189+
"""
190+
contents = [
191+
('mouse1', '2020-12-01 12:32:34', ''),
192+
('mouse1', '2020-12-02 12:32:34', ''),
193+
('mouse1', '2020-12-03 12:32:34', ''),
194+
('mouse1', '2020-12-04 12:32:34', '')
195+
]
196+
197+
@schema
198+
class SessionStatus(dj.Lookup):
199+
definition = """
200+
-> Session
201+
---
202+
status: enum('in_training', 'trained_1a', 'trained_1b', 'ready4ephys')
203+
"""
204+
contents = [
205+
('mouse1', '2020-12-01 12:32:34', 'in_training'),
206+
('mouse1', '2020-12-02 12:32:34', 'trained_1a'),
207+
('mouse1', '2020-12-03 12:32:34', 'trained_1b'),
208+
('mouse1', '2020-12-04 12:32:34', 'ready4ephys'),
209+
]
210+
211+
@schema
212+
class SessionDate(dj.Lookup):
213+
definition = """
214+
-> Subject
215+
session_date: date
216+
"""
217+
contents = [
218+
('mouse1', '2020-12-01'),
219+
('mouse1', '2020-12-02'),
220+
('mouse1', '2020-12-03'),
221+
('mouse1', '2020-12-04')
222+
]
223+
224+
subjects = Subject.aggr(
225+
SessionStatus & 'status="trained_1a" or status="trained_1b"',
226+
date_trained='min(date(session_start_time))')
227+
228+
print(f'subjects: {subjects}')
229+
print(f'SessionDate: {SessionDate()}')
230+
print(f'join: {SessionDate * subjects}')
231+
print(f'join query: {(SessionDate * subjects).make_sql()}')
232+
162233
@staticmethod
163234
def test_project():
164235
x = A().proj(a='id_a') # rename
@@ -467,6 +538,12 @@ def test_complex_date_restriction():
467538
"""Test a complex date restriction"""
468539
q = OutfitLaunch & 'day between curdate() - interval 30 day and curdate()'
469540
assert len(q) == 1
541+
q = OutfitLaunch & 'day between curdate() - interval 4 week and curdate()'
542+
assert len(q) == 1
543+
q = OutfitLaunch & 'day between curdate() - interval 1 month and curdate()'
544+
assert len(q) == 1
545+
q = OutfitLaunch & 'day between curdate() - interval 1 year and curdate()'
546+
assert len(q) == 1
470547
q = OutfitLaunch & '`day` between curdate() - interval 30 day and curdate()'
471548
assert len(q) == 1
472549
q.delete()

0 commit comments

Comments
 (0)