Commit 88a02ed2 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Separate out description generation, use column metadata if present. Fix

to icd10DescriptionFromCode
parent a46df4a2
......@@ -419,25 +419,45 @@ def doDescriptionExport(dtable, args):
with util.timed('Description export', log):
cols = dtable.allColumns[1:]
vartable = dtable.vartable
cols = dtable.allColumns[1:]
with open(args.description_file, 'wt') as f:
for c in cols:
desc = vartable.loc[c.vid, 'Description']
if desc ==
desc = 'n/a'
f.write('{}\t{}\n'.format(, desc))
for col in cols:
desc = generateDescription(dtable, col)
f.write('{}\t{}\n'.format(, desc))
except Exception as e:
log.warning('Failed to export descriptions: {}'.format(e),
def generateDescription(dtable, col):
"""Called by :func:`doDescriptionExport`. Generates and returns a
suitable description for the given column.
:arg dtable: :class:`.Datatable` instance
:arg col: :class:`.Column` instance
vartable = dtable.vartable
desc = vartable.loc[col.vid, 'Description']
if desc ==
desc = 'n/a'
# If metadata has been added to the column,
# we add it to the description. See the
# binariseCategorical processing function
# for an example of this.
if col.metadata is not None:
suffix = ' ({})'.format(col.metadata)
suffix = ' ({}.{})'.format(col.visit, col.instance)
return '{}{}'.format(desc, suffix)
def configLogging(args):
"""Configures ``ukbparse`` logging.
......@@ -367,7 +367,6 @@ def icd10DescriptionFromNumeric(val):
def icd10DescriptionFromCode(val):
"""Generates a description for an ICD10 code. """
val = icd10.codeToNumeric(val)
hier = hierarchy.getHierarchyFilePath(name='icd10')
hier = hierarchy.loadHierarchyFile(hier)
desc = hier.description(val)
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