def clean_unit_errors(merged_df):
    """
    This function will look in a DataFrame for rows where the height_cat and weight_cat are set to
    "Unit-Error-High" or "Unit-Error-Low". It will then multiply / divide the height and weight
    values to convert them.  It will also create two new columns: postprocess_height_cat and
    postprocess_weight_cat.  The values for these columns are copied from the original categories
    except in the case where unit errors are fixed when it is set to "Include-UH" or "Include-UL"
    respectively.

    At present, the adult algorithm does not specify high or low unit errors, rather it only flags
    "Exclude-Adult-Unit-Errors", so this function only works with pediatrics data. If growthcleanr
    adds high and low designations for adult unit errors, a comparable set of conditions could be
    added here to accommodate adult data.

    Parameters:
    merged_df: (DataFrame) with subjid, height, weight, include_height and include_weight columns

    Returns:
    The cleaned DataFrame
    """
    merged_df["postprocess_height_cat"] = merged_df["height_cat"]
    merged_df["postprocess_height_cat"] = merged_df[
        "postprocess_height_cat"
    ].cat.add_categories(["Include-UH", "Include-UL"])
    merged_df["postprocess_weight_cat"] = merged_df["weight_cat"]
    merged_df["postprocess_weight_cat"] = merged_df[
        "postprocess_weight_cat"
    ].cat.add_categories(["Include-UH", "Include-UL"])
    merged_df.loc[merged_df["height_cat"] == "Unit-Error-Low", "height"] = (
        merged_df.loc[merged_df["height_cat"] == "Unit-Error-Low", "height"] * 2.54
    )
    merged_df.loc[merged_df["height_cat"] == "Unit-Error-High", "height"] = (
        merged_df.loc[merged_df["height_cat"] == "Unit-Error-High", "height"] / 2.54
    )
    merged_df.loc[merged_df["weight_cat"] == "Unit-Error-Low", "weight"] = (
        merged_df.loc[merged_df["weight_cat"] == "Unit-Error-Low", "weight"] * 2.2046
    )
    merged_df.loc[merged_df["weight_cat"] == "Unit-Error-High", "weight"] = (
        merged_df.loc[merged_df["weight_cat"] == "Unit-Error-High", "weight"] / 2.2046
    )
    merged_df.loc[
        merged_df["height_cat"] == "Unit-Error-Low", "postprocess_height_cat"
    ] = "Include-UL"
    merged_df.loc[
        merged_df["height_cat"] == "Unit-Error-High", "postprocess_height_cat"
    ] = "Include-UH"
    merged_df.loc[
        merged_df["weight_cat"] == "Unit-Error-Low", "postprocess_weight_cat"
    ] = "Include-UL"
    merged_df.loc[
        merged_df["weight_cat"] == "Unit-Error-High", "postprocess_weight_cat"
    ] = "Include-UH"
    merged_df["bmi"] = merged_df["weight"] / ((merged_df["height"] / 100) ** 2)
    return merged_df