Commit 571937f5 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: flattenHierarchical allows hierarchy name to be specified

parent 778fdab8
......@@ -176,13 +176,15 @@ def fillMissing(dtable, vid, value):
def flattenHierarchical(dtable, vid, level=None):
def flattenHierarchical(dtable, vid, level=None, name=None):
Replace leaf values with parent values in hierarchical variables.
For hierarchical variables such as the ICD10 disease categorisations,
this function replaces leaf values with a parent value.
The ``name`` argument allows the hierarchy data type to be specified.
The ``level`` argument allows the depth of the parent value to be selected
- ``0`` (the default) replaces a value with the top-level (i.e. its most
distant) parent value, ``1`` the second-level parent value, etc.
......@@ -195,7 +197,7 @@ def flattenHierarchical(dtable, vid, level=None):
level = 0
columns = [ for c in dtable.columns(vid)]
vhier = hierarchy.getHierarchyFilePath(dtable, vid)
vhier = hierarchy.getHierarchyFilePath(dtable, vid, name)
vhier = hierarchy.loadHierarchyFile(vhier)
def index_parent(parents, coding):
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