Skip to content

Commit a3b7c65

Browse files
author
Chris Turner
committed
tests/test_relation.py: add user-created pd.DataFrame test for #666
1 parent 172f4bf commit a3b7c65

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/test_relation.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def test_insert_select(self):
103103
'real_id', 'date_of_birth', 'subject_notes', subject_id='subject_id+1000', species='"human"'))
104104
assert_equal(len(self.subject), 2*original_length)
105105

106-
def test_insert_pandas(self):
106+
def test_insert_pandas_roundtrip(self):
107+
# ensure fetched frames can be inserted
107108
schema.TTest2.delete()
108109
n = len(schema.TTest())
109110
assert_true(n > 0)
@@ -113,6 +114,18 @@ def test_insert_pandas(self):
113114
schema.TTest2.insert(df)
114115
assert_equal(len(schema.TTest2()), n)
115116

117+
def test_insert_pandas_userframe(self):
118+
# ensure simple user-created frames (1 field, non-custom index)
119+
# can be inserted without extra index adjustment
120+
schema.TTest2.delete()
121+
n = len(schema.TTest())
122+
assert_true(n > 0)
123+
df = pandas.DataFrame(schema.TTest.fetch())
124+
assert_true(isinstance(df, pandas.DataFrame))
125+
assert_equal(len(df), n)
126+
schema.TTest2.insert(df)
127+
assert_equal(len(schema.TTest2()), n)
128+
116129
@raises(dj.DataJointError)
117130
def test_insert_select_ignore_extra_fields0(self):
118131
""" need ignore extra fields for insert select """

0 commit comments

Comments
 (0)