Commit e0196614 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: What was i thinking? Reverted DataTable.merge to use .loc-based assignment

instead of drop+concat. Also only consider columns that have been modified,
and no-op if no columns have changed.
parent d877dbb0
......@@ -646,55 +646,32 @@ class DataTable(util.Singleton):
def merge(self, subtable):
"""Merge the data from the given ``subtable`` into this ``DataTable``.
It is assumed that ``subtable`` contains a sub-set of the columns
in this ``DataTable``.
:arg subtable: ``DataTable`` returned by :meth:`subtable`.
"""
if self.shape[0] == subtable.shape[0]:
subrows = None
subrows = slice(None)
else:
subrows = subtable.index
if self.shape[1] == subtable.shape[1]:
subcols = None
else:
subcols = [c.name for c in subtable.dataColumns]
# subtable == main table?
if (subrows is None) and (subcols is None):
self.__data = subtable[:, :]
# if subject indices match, we
# can use pd.concat to merge
# the two dataframes fast.
elif subrows is None:
# take a copy of the column names
# so we can restore their ordering
origcols = self.__data.columns
self.__data = self.__data.drop(columns=subcols)
self.__data = pd.concat((self.__data, subtable[:, :]),
axis=1,
copy=False,
verify_integrity=False)
# restore column ordering
self.__data = self.__data[origcols]
# otherwise we perform slower
# df.loc based assignment
# (slower, because data copying
# has to take place)
else:
if subcols is None:
subcols = slice(None)
self[subrows, subcols] = subtable[subrows, subcols]
# only copy modified columns - we assume
# that all changes to the subtable
# occurred via DataTable.__setitem__
subcols = [c.name for c in subtable.dataColumns
if MODIFIED_COLUMN in subtable.getFlags(c)]
if len(subcols) > 0:
self.__data.loc[subrows, subcols] = subtable[subrows, subcols]
for subcol in subtable.dataColumns:
mycol = self.__colmap[subcol.name]
myflags = self.__flags[mycol]
subflags = subtable.getFlags(subcol)
subflags = subflags.difference((MODIFIED_COLUMN,))
self.__flags[mycol] = myflags.union(subflags)
if subcol.metadata is not None:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment