|
6 | 6 | import pandas |
7 | 7 | import warnings |
8 | 8 | from . import schema |
| 9 | +from .schema import Parent, Stimulus |
9 | 10 | import datajoint as dj |
10 | 11 | import os |
11 | 12 |
|
@@ -287,3 +288,34 @@ def test_query_caching(self): |
287 | 288 |
|
288 | 289 | # reset cache directory state (will fail if purge was unsuccessful) |
289 | 290 | os.rmdir(os.path.expanduser('~/dj_query_cache')) |
| 291 | + |
| 292 | + def test_fetch_group_by(self): |
| 293 | + # https://github.com/datajoint/datajoint-python/issues/914 |
| 294 | + |
| 295 | + assert Parent().fetch('KEY', order_by='name') == [{'parent_id': 1}] |
| 296 | + |
| 297 | + def test_dj_u_distinct(self): |
| 298 | + # Test developed to see if removing DISTINCT from the select statement |
| 299 | + # generation breakes the dj.U universal set imlementation |
| 300 | + |
| 301 | + # Contents to be inserted |
| 302 | + contents = [ |
| 303 | + (1,2,3), |
| 304 | + (2,2,3), |
| 305 | + (3,3,2), |
| 306 | + (4,5,5) |
| 307 | + ] |
| 308 | + Stimulus.insert(contents) |
| 309 | + |
| 310 | + # Query the whole table |
| 311 | + test_query = Stimulus() |
| 312 | + |
| 313 | + # Use dj.U to create a list of unique contrast and brightness combinations |
| 314 | + result = dj.U('contrast', 'brightness') & test_query |
| 315 | + expected_result = [{'contrast': 2, 'brightness': 3}, |
| 316 | + {'contrast': 3, 'brightness': 2}, |
| 317 | + {'contrast': 5, 'brightness': 5}] |
| 318 | + |
| 319 | + fetched_result = result.fetch(as_dict=True, order_by=('contrast', 'brightness')) |
| 320 | + Stimulus.delete_quick() |
| 321 | + assert fetched_result == expected_result |
0 commit comments