Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
701bf76
fix #483 and #516: .proj() preserves original order. Also rename cla…
dimitri-yatsenko Nov 13, 2018
38f1dba
Merge branch 'dev'
dimitri-yatsenko Nov 13, 2018
08e61e6
complete renaming query -> expression
dimitri-yatsenko Nov 13, 2018
025dd93
rename class Expression -> QueryExpression
dimitri-yatsenko Nov 13, 2018
1d5b593
add test for create_virtual_module and for issue #516
dimitri-yatsenko Nov 13, 2018
f0c8b8f
Merge branch 'master' of https://github.com/datajoint/datajoint-python
dimitri-yatsenko Nov 13, 2018
a348758
fix doc strings to use QueryExpression
dimitri-yatsenko Nov 13, 2018
8edb4d7
add test for QueryExpression iterator
dimitri-yatsenko Nov 13, 2018
85dca73
finish renaming query -> expression in fetch.py
dimitri-yatsenko Nov 13, 2018
470682a
update version and CHANGELOG for release 0.11.1
dimitri-yatsenko Nov 13, 2018
65ea0e7
minor
dimitri-yatsenko Nov 13, 2018
8cca325
minor
dimitri-yatsenko Nov 14, 2018
77644ee
increase timeout for nosetests in travis
dimitri-yatsenko Nov 14, 2018
b46b64b
change terminology from `relations` to `query expressions` in doc str…
dimitri-yatsenko Nov 14, 2018
277398f
undo travis setting -- travis still not working on GitHub
dimitri-yatsenko Nov 16, 2018
06d5cc3
undo inconsequential change from previous commit to try to figure out…
dimitri-yatsenko Nov 16, 2018
10f7393
simplify context management, move test initialization into setup_clas…
dimitri-yatsenko Nov 17, 2018
29ca4c9
remove make_module_code for lack of potential use, tagging this commi…
dimitri-yatsenko Nov 17, 2018
bae0900
remove erd.topological_sort -- it is never called
dimitri-yatsenko Nov 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
finish renaming query -> expression in fetch.py
  • Loading branch information
dimitri-yatsenko committed Nov 13, 2018
commit 85dca730d3bb8b06ed3552839dc50b3687ae6bf7
16 changes: 8 additions & 8 deletions datajoint/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Fetch:
"""

def __init__(self, expression):
self._query = expression
self._expression = expression

def __call__(self, *attrs, offset=None, limit=None, order_by=None, as_dict=False, squeeze=False):
"""
Expand Down Expand Up @@ -52,12 +52,12 @@ def __call__(self, *attrs, offset=None, limit=None, order_by=None, as_dict=False
if limit is None and offset is not None:
warnings.warn('Offset set, but no limit. Setting limit to a large number. '
'Consider setting a limit explicitly.')
limit = 2 * len(self._query)
limit = 2 * len(self._expression)

if not attrs:
# fetch all attributes
cur = self._query.cursor(as_dict=as_dict, limit=limit, offset=offset, order_by=order_by)
heading = self._query.heading
cur = self._expression.cursor(as_dict=as_dict, limit=limit, offset=offset, order_by=order_by)
heading = self._expression.heading
if as_dict:
ret = [OrderedDict((name, unpack(d[name], squeeze=squeeze) if heading[name].is_blob else d[name])
for name in heading.names)
Expand All @@ -67,16 +67,16 @@ def __call__(self, *attrs, offset=None, limit=None, order_by=None, as_dict=False
ret = np.array(ret, dtype=heading.as_dtype)
for name in heading:
if heading[name].is_external:
external_table = self._query.connection.schemas[heading[name].database].external_table
external_table = self._expression.connection.schemas[heading[name].database].external_table
ret[name] = list(map(external_table.get, ret[name]))
elif heading[name].is_blob:
ret[name] = list(map(partial(unpack, squeeze=squeeze), ret[name]))
else: # if list of attributes provided
attributes = [a for a in attrs if not is_key(a)]
result = self._query.proj(*attributes).fetch(
result = self._expression.proj(*attributes).fetch(
offset=offset, limit=limit, order_by=order_by, as_dict=False, squeeze=squeeze)
return_values = [
list(to_dicts(result[self._query.primary_key]))
list(to_dicts(result[self._expression.primary_key]))
if is_key(attribute) else result[attribute]
for attribute in attrs]
ret = return_values[0] if len(attrs) == 1 else return_values
Expand All @@ -90,7 +90,7 @@ def keys(self, **kwargs):
"""
warnings.warn('Use of `rel.fetch.keys()` notation is deprecated. '
'Please use `rel.fetch("KEY")` or `rel.fetch(dj.key)` for equivalent result', stacklevel=2)
yield from self._query.proj().fetch(as_dict=True, **kwargs)
yield from self._expression.proj().fetch(as_dict=True, **kwargs)


class Fetch1:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_blob2.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __init__(self):

@staticmethod
def test_complex_matlab_blobs():
"""
test correct de-serialization of various blob types
"""
blobs = Blob().fetch('blob', order_by='id')
assert_equal(blobs[0][0], 'character string')
assert_true(np.array_equal(blobs[1][0], np.r_[1:180:15]))
Expand Down