Skip to content

Commit 172f4bf

Browse files
author
Chris Turner
committed
datajoint/table.py: update pandas index conversion logic per #776 discussion
1 parent 95a705c commit 172f4bf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

datajoint/table.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ def insert(self, rows, replace=False, skip_duplicates=False, ignore_extra_fields
193193
"""
194194

195195
if isinstance(rows, pandas.DataFrame):
196+
# drop 'extra' synthetic index for 1-field index case -
197+
# frames with more advanced indices should be prepared by user.
196198
rows = rows.reset_index(
197-
drop=isinstance(rows.index, pandas.RangeIndex)).to_records(
198-
index=False)
199+
drop=len(rows.index.names) == 1 and not rows.index.names[0]
200+
).to_records(index=False)
199201

200202
# prohibit direct inserts into auto-populated tables
201203
if not allow_direct_insert and not getattr(self, '_allow_insert', True): # allow_insert is only used in AutoPopulate

0 commit comments

Comments
 (0)