Commit 835dc7fc authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Exporter functions now accept a dict of oldcol:newcol mappings, instead of

a sequence of new column names
parent c10e82c4
......@@ -132,7 +132,6 @@ def exportData(dtable,
subjects = [s for s in subjects if s in dtable.index]
colnames = genColumnNames(dtable, colpat, colmap)
colnames = [colnames[c.name] for c in dtable.allColumns[1:]]
custom.runExporter(
fileFormat, dtable, outfile, subjects, idcol, colnames, **kwargs)
......
......@@ -59,7 +59,7 @@ def exportHDF5(dtable,
:arg idcol: Name to use for the subject ID column
:arg colnames: Sequence containing column names
:arg colnames: Dict containing ``{oldcol : newcol}`` mappings
:arg key: Name to give the HDF5 group. Defaults to :attr:`HDF5_KEY`.
......@@ -115,7 +115,7 @@ def exportPandasStyle(dtable,
:arg idcol: Name to use for the subject ID column
:arg colnames: Sequence containing column names
:arg colnames: Dict containing ``{oldcol : newcol}`` mappings
:arg key: Name to give the HDF5 group.
......@@ -128,9 +128,7 @@ def exportPandasStyle(dtable,
with pd.HDFStore(outfile, 'w') as s:
nchunks = int(np.ceil(len(subjects) / numRows))
oldcols = [c.name for c in dtable.allColumns[1:]]
colnames = {oc : nc for oc, nc in zip(oldcols, colnames)}
nchunks = int(np.ceil(len(subjects) / numRows))
log.info('Writing %u columns in %u chunk(s) to %s ...',
len(dtable.allColumns), nchunks, outfile)
......@@ -170,7 +168,7 @@ def exportFunpackStyle(dtable,
:arg idcol: Name to use for the subject ID column
:arg colnames: Sequence containing column names
:arg colnames: Dict containing ``{oldcol : newcol}`` mappings
:arg key: Name to give the HDF5 group.
......@@ -193,9 +191,9 @@ def exportFunpackStyle(dtable,
data = np.asarray(subjects)
f.create_dataset(name, data=data)
for i, col in enumerate(dtable.allColumns[1:]):
for col in dtable.allColumns[1:]:
name = '/'.join((key, colnames[i]))
name = '/'.join((key, colnames.get(col.name, col.name)))
series = dtable[subjects, col.name]
vid = col.vid
formatter = None
......
......@@ -47,7 +47,7 @@ def exportTSV(dtable,
:arg idcol: Name to use for the subject ID column
:arg colnames: Sequence containing column names
:arg colnames: Dict containing ``{oldcol : newcol}`` mappings
:arg sep: Separator character to use. Defaults to
:attr:`TSV_SEP`
......
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