Skip to content

Commit 9e6cd0e

Browse files
Merge pull request #774 from gucky92/fetch_format_bug
fix when fetch_format='frame'
2 parents 8e289c6 + f90473d commit 9e6cd0e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

datajoint/fetch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def __call__(self, *attrs, offset=None, limit=None, order_by=None, format=None,
173173
attributes = [a for a in attrs if not is_key(a)]
174174
ret = self._expression.proj(*attributes).fetch(
175175
offset=offset, limit=limit, order_by=order_by,
176-
as_dict=False, squeeze=squeeze, download_path=download_path)
176+
as_dict=False, squeeze=squeeze, download_path=download_path,
177+
format='array'
178+
)
177179
if attrs_as_dict:
178180
ret = [{k: v for k, v in zip(ret.dtype.names, x) if k in attrs} for x in ret]
179181
else:

tests/test_fetch.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,27 @@ def test_nullable_numbers(self):
220220
assert_true(None in i)
221221
assert_true(any(np.isnan(d)))
222222
assert_true(any(np.isnan(f)))
223+
224+
def test_fetch_format(self):
225+
"""test fetch_format='frame'"""
226+
dj.config['fetch_format'] = 'frame'
227+
# test if lists are both dicts
228+
list1 = sorted(self.subject.proj().fetch(as_dict=True), key=itemgetter('subject_id'))
229+
list2 = sorted(self.subject.fetch(dj.key), key=itemgetter('subject_id'))
230+
for l1, l2 in zip(list1, list2):
231+
assert_dict_equal(l1, l2, 'Primary key is not returned correctly')
232+
233+
# tests if pandas dataframe
234+
tmp = self.subject.fetch(order_by='subject_id')
235+
assert_true(isinstance(tmp, pandas.DataFrame))
236+
tmp = tmp.to_records()
237+
238+
subject_notes, key, real_id = self.subject.fetch('subject_notes', dj.key, 'real_id')
239+
240+
np.testing.assert_array_equal(sorted(subject_notes), sorted(tmp['subject_notes']))
241+
np.testing.assert_array_equal(sorted(real_id), sorted(tmp['real_id']))
242+
list1 = sorted(key, key=itemgetter('subject_id'))
243+
for l1, l2 in zip(list1, list2):
244+
assert_dict_equal(l1, l2, 'Primary key is not returned correctly')
245+
# revert configuration of fetch format
246+
dj.config['fetch_format'] = 'array'

0 commit comments

Comments
 (0)