@@ -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