Merge pull request #305 from abmyii/retain_columns_order

Use lists instead of sets to maintain order of column names
This commit is contained in:
Friedrich Lindenberg 2020-01-11 11:51:45 +01:00 committed by GitHub
commit 901d6a99d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,7 +132,7 @@ class Table(object):
sync_row = {}
for row in rows:
# Only get non-existing columns.
for key in set(row.keys()).difference(set(sync_row.keys())):
for key in [k for k in row.keys() if k not in sync_row.keys()]:
# Get a sample of the new column(s) from the row.
sync_row[key] = row[key]
self._sync_columns(sync_row, ensure, types=types)
@ -192,10 +192,10 @@ class Table(object):
keys = keys if type(keys) in (list, tuple) else [keys]
chunk = []
columns = set()
columns = []
for index, row in enumerate(rows):
chunk.append(row)
columns = columns.union(set(row.keys()))
columns = [col for col in row.keys() if col not in columns]
# bindparam requires names to not conflict (cannot be "id" for id)
for key in keys: