Skip to content

v0.6.1

Latest

Choose a tag to compare

@amc-corey-cox amc-corey-cox released this 30 Nov 21:52
fe286e2

This release adds two things a spec couldn't say before: which rows a class derivation applies to, and what a slot should hold when its source value is missing or unmapped. Both came out of getting BDC output to validate against BDCHM. Nothing changes for a spec that doesn't use them.

Filtering rows

A class derivation maps every row of its table. filter_rows is an expression evaluated on each source row, and a row where it isn't true yields no object: no record at the top level, and no nested object under a slot. (#407)

class_derivations:
  Visit:
    populated_from: exams
    filter_rows: "{exam} == 1"
    slot_derivations:
      id:
        expr: "{pid} + ':exam1'"
  • It reads joined tables like any expression ({people.cohort} == "original").
  • A filter that evaluates to None rejects the row, so an ordering comparison on an empty cell ({exam} >= 1) drops it. == and != compare None like any other value, so {exam} != 2 keeps rows where exam is empty; guard with {exam} is not None and ... to drop them.
  • It runs before any slot is derived, so calling slot() in a filter is an error. It also runs before a pivot_operation.
  • A filter that fails to evaluate is a row error, reported like a slot error.
  • validate-spec checks the names a filter reads, and map-data logs a warning when a filter keeps none of the rows it saw. That can be correct on a subset of a study, so it never fails the run, even under --strict.

See Filtering Rows.

Filling missing and unmapped values

Two SlotDerivation fields fill a populated_from slot that would otherwise come out null. (#408)

  • value_if_missing: used when the source value is missing, meaning an empty cell, an absent column, or a code nulled by missing_values.
  • value_if_unmapped: used when a present value matches no key in value_mappings or expression_mappings.
condition_status:
  populated_from: phv00203303
  value_mappings:
    '0': ABSENT
    '1': PRESENT
  value_if_missing: UNKNOWN
  value_if_unmapped: UNKNOWN
  • The fill is a target value. It goes through the same range coercion and enum resolution as a mapped value, but value_mappings and offset aren't applied to it.
  • validate-spec checks both fills against the target enum, like value_mappings values.
  • They apply only to populated_from slots, like missing_values.

Known issues

  • A value_mappings result, or one of the new fills, comes out null when the source slot's range is an enum that has an enum derivation. (#413)
  • Under --unrestricted-eval, a filter_rows that fails to evaluate rejects the row instead of raising. The "kept none of N rows" warning is the only signal.

Full changelog: v0.6.0...v0.6.1