[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BZ1SVE1QQPX0AM4J95DGSQ":3,"skill-same:01M7BZ1SVE1QQPX0AM4J95DGSQ":51},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7BZ1SVE1QQPX0AM4J95DGSQ","lab-unit-harmonization",null,"Comprehensive clinical laboratory data harmonization for multi-source healthcare analytics. Convert between US conventional and SI units, standardize numeric formats, and clean data quality issues. This skill should be used when you need to harmonize lab values from different sources, convert units for clinical analysis, fix formatting inconsistencies (scientific notation, decimal separators, whitespace), or prepare lab panels for research.","linyouxue\u002Fskill-repair-benchmark","linyouxue","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F216151464?v=4","01M7BJEVCXKD74KH6FG9CBVSQB","林宥学","01M7BJEVE02NP217V93BKZFC0J",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Flab-unit-harmonization\u002Frepaired_run\u002Finputs\u002Fskills\u002Flab-unit-harmonization\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: lab-unit-harmonization\ndescription: Comprehensive clinical laboratory data harmonization for multi-source healthcare analytics. Convert between US conventional and SI units, standardize numeric formats, and clean data quality issues. This skill should be used when you need to harmonize lab values from different sources, convert units for clinical analysis, fix formatting inconsistencies (scientific notation, decimal separators, whitespace), or prepare lab panels for research.\n---\n\n# Lab Unit Harmonization\n\n## Overview\n\nLab Unit Harmonization provides techniques and references for standardizing clinical laboratory data from multiple sources. Real-world healthcare data often contains measurements in different units, varying decimal and numeric formats, and data entry inconsistencies that must be resolved before analysis.\n\nThis skill covers:\n- **Unit Conversion**: Converting between US conventional and SI units\n- **Format Standardization**: Handling scientific notation, decimal formats, whitespace\n- **Data Quality Assessment**: Identifying and quantifying data issues\n- **CKD-Specific Labs**: Practical references for chronic kidney disease-related lab features\n\n## When to Use This Skill\n\nUse this skill when:\n- Harmonizing lab values from multiple hospitals or health systems\n- Converting between US conventional and SI units (e.g., mg\u002FdL to µmol\u002FL)\n- Merging data from EHRs using different default unit conventions\n- Integrating international datasets with mixed unit systems\n- Standardizing inconsistent numeric formats (scientific notation, decimals)\n- Cleaning whitespace, thousand separators, or European decimal formats\n- Validating lab values against expected clinical ranges\n- Preparing CKD lab panels for eGFR calculations or staging models\n- Building ETL pipelines for clinical data warehouses\n- Preprocessing lab data for machine learning models\n\n## Data Quality Issues Reference\n\nReal-world clinical lab data contains multiple types of quality issues. The following table summarizes common issues and their typical prevalence in multi-source datasets:\n\n| Issue Type | Description | Typical Prevalence | Example |\n|------------|-------------|-------------------|---------|\n| **Incomplete Records** | Rows with excessive missing values | 1-5% | Patient record with only 3\u002F62 labs measured |\n| **Mixed Units** | Same analyte reported in different units | 20-40% | Creatinine: mg\u002FdL vs µmol\u002FL |\n| **Scientific Notation** | Large\u002Fsmall values in exponential format | 15-30% | `1.5e3` instead of `1500` |\n| **Thousand Separators** | Commas in large numbers | 10-25% | `1,234.5` vs `1234.5` |\n| **European Decimals** | Comma as decimal separator | 10-20% | `12,5` instead of `12.5` |\n| **Whitespace Issues** | Leading\u002Ftrailing spaces, tabs | 15-25% | `  45.2 ` vs `45.2` |\n| **Missing Values** | Empty, NULL, or sentinel values | Variable | `NaN`, `-999`, blank |\n\n### Features with Multiple Alternative Units\n\nSome features have more than two possible unit representations:\n\n**Three-Unit Features (8 total):**\n| Feature | Unit 1 | Unit 2 | Unit 3 |\n|---------|--------|--------|--------|\n| Magnesium | mg\u002FdL | mmol\u002FL | mEq\u002FL |\n| Serum_Calcium | mg\u002FdL | mmol\u002FL | mEq\u002FL |\n| Hemoglobin | g\u002FdL | g\u002FL | mmol\u002FL |\n| Ferritin | ng\u002FmL | µg\u002FL | pmol\u002FL |\n| Prealbumin | mg\u002FdL | mg\u002FL | g\u002FL |\n| Urine_Creatinine | mg\u002FdL | µmol\u002FL | mmol\u002FL |\n| Troponin_I | ng\u002FmL | µg\u002FL | ng\u002FL |\n| Troponin_T | ng\u002FmL | µg\u002FL | ng\u002FL |\n\n## Core Workflow\n\nThe harmonization process follows these steps in order:\n\n### Step 0: Filter Incomplete Records (Preprocessing)\n\nBefore harmonization, filter out rows with any missing values:\n\n```python\ndef count_missing(row, numeric_cols):\n    \"\"\"Count missing\u002Fempty values in numeric columns\"\"\"\n    count = 0\n    for col in numeric_cols:\n        val = row[col]\n        if pd.isna(val) or str(val).strip() in ['', 'NaN', 'None', 'nan', 'none']:\n            count += 1\n    return count\n\n# Keep only rows with NO missing values\nmissing_counts = df.apply(lambda row: count_missing(row, numeric_cols), axis=1)\ncomplete_mask = missing_counts == 0\ndf = df[complete_mask].reset_index(drop=True)\n```\n\n**Rationale**: Clinical datasets often contain incomplete records (e.g., partial lab panels, cancelled orders, data entry errors). For harmonization tasks, only complete records with all features measured can be reliably processed. Rows with any missing values should be excluded to ensure consistent output quality.\n\n### Step 1: Parse Numeric Formats\n\nParse all raw values to clean floats. In mixed-source lab data you must handle both **European decimal commas** and **thousand separators**.\n\n**Parsing rules (robust + transferable):**\n1. Strip whitespace.\n2. If both `,` and `.` appear, treat `,` as a **thousand separator** and remove it (e.g., `\"1,234.5\" → \"1234.5\"`).\n3. Else if only `,` appears, treat it as a **decimal separator** (e.g., `\"12,34\" → \"12.34\"`).\n4. Then parse with `float()` (this also handles scientific notation like `1.23e2`).\n\n```python\nimport pandas as pd\nimport numpy as np\nimport re\n\n_MISSING = {'', 'nan','NaN','None','NULL','null','NA','N\u002FA'}\n_KEEP_NUM = re.compile(r'[^0-9eE+\\-\\.,]')\n\ndef parse_value(value):\n    \"\"\"Parse a raw value to float with comma\u002Fdot disambiguation.\"\"\"\n    if pd.isna(value):\n        return np.nan\n\n    s = str(value).strip()\n    if s in _MISSING or s.lower() == 'nan':\n        return np.nan\n\n    # Remove stray unit symbols or other junk while keeping numeric structure\n    s = _KEEP_NUM.sub('', s)\n\n    # Disambiguate comma\n    if ',' in s and '.' in s:\n        # comma is thousands separator\n        s = s.replace(',', '')\n    elif ',' in s:\n        # comma is decimal separator\n        s = s.replace(',', '.')\n\n    try:\n        return float(s)\n    except ValueError:\n        return np.nan\n\nfor col in numeric_cols:\n    df[col] = df[col].apply(parse_value)\n```\n\n### Step 2: Unit Conversion (Range-Based Detection)\n\n**Key Principle**: If a value falls outside the expected physiological range in **US conventional** units, it may need unit conversion.\n\nHowever, range-based detection only works if you supply (1) correct target ranges and (2) plausible alternate-unit conversions for that analyte.\n\n#### 2A) Provide target ranges (US conventional) and plausible alternate conversions\n\nIf you do not have an external reference file available at runtime, use an internal mapping for the features you are harmonizing.\n\nBelow is a **minimal, high-impact CKD panel mapping** covering analytes that commonly appear in mixed units and that frequently break downstream range checks if mishandled.\n\n> Notes:\n> - These are intended as *physiologic plausibility windows* for harmonization, not clinical decision limits.\n> - Some analytes (e.g., urine protein) have very wide plausible ranges; conversions are still needed because unit mixes can be orders of magnitude.\n\n**Target ranges (US conventional) used for harmonization checks:**\n\n| Feature | Target unit | Expected physiological range |\n|---|---:|---:|\n| BUN | mg\u002FdL | 5 – 200 |\n| Serum_Calcium (total) | mg\u002FdL | 5 – 15 |\n| Ionized_Calcium | mmol\u002FL | 0.8 – 2.0 |\n| Intact_PTH | pg\u002FmL | 5 – 2500 |\n| Vitamin_D_1_25OH | pg\u002FmL | 5 – 100 |\n| Hemoglobin | g\u002FdL | 3 – 20 |\n| Ferritin | ng\u002FmL (≈ µg\u002FL) | 5 – 5000 |\n| Prealbumin | mg\u002FdL | 5 – 50 |\n| Triglycerides | mg\u002FdL | 30 – 2000 |\n| Urine_Creatinine | mg\u002FdL | 10 – 500 |\n| Urine_Protein | mg\u002FL | 0 – 3000 |\n| Troponin_I | ng\u002FmL | 0 – 50 |\n| Troponin_T | ng\u002FmL | 0 – 10 |\n| pCO2_Arterial | mmHg | 15 – 100 |\n| pO2_Arterial | mmHg | 30 – 500 |\n| Lactate | mmol\u002FL | 0.3 – 20 |\n\n**Common alternate units and conversion factors** (multiply by factor to reach target unit):\n\n| Feature | Alternate unit(s) commonly seen | Convert to target (multiply) |\n|---|---|---:|\n| BUN | mmol\u002FL (urea nitrogen) | `× 2.801` (mmol\u002FL → mg\u002FdL) |\n| Serum_Calcium | mmol\u002FL | `× 4.0` (mmol\u002FL → mg\u002FdL) |\n| Ionized_Calcium | mg\u002FdL | `× 0.2495` (mg\u002FdL → mmol\u002FL) |\n| Intact_PTH | pmol\u002FL | `× 9.43` (pmol\u002FL → pg\u002FmL) *(assay-dependent; use as plausibility conversion)* |\n| Vitamin_D_1_25OH | pmol\u002FL | `× 0.4167` (pmol\u002FL → pg\u002FmL) *(approx; use for harmonization plausibility)* |\n| Hemoglobin | g\u002FL | `× 0.1` (g\u002FL → g\u002FdL) |\n| Ferritin | pmol\u002FL | `× 0.445` (pmol\u002FL → ng\u002FmL) *(approx; plausibility conversion)* |\n| Prealbumin | g\u002FL | `× 100.0` (g\u002FL → mg\u002FdL) |\n| Triglycerides | mmol\u002FL | `× 88.57` (mmol\u002FL → mg\u002FdL) |\n| Urine_Creatinine | µmol\u002FL | `× 0.0113` (µmol\u002FL → mg\u002FdL) |\n| Urine_Creatinine | mmol\u002FL | `× 113.0` (mmol\u002FL → mg\u002FdL) |\n| Urine_Protein | mg\u002FdL | `× 10.0` (mg\u002FdL → mg\u002FL) |\n| Urine_Protein | g\u002FL | `× 1000.0` (g\u002FL → mg\u002FL) |\n| Troponin_I | ng\u002FL | `× 0.001` (ng\u002FL → ng\u002FmL) |\n| Troponin_T | ng\u002FL | `× 0.001` (ng\u002FL → ng\u002FmL) |\n| pCO2_Arterial | kPa | `× 7.5006` (kPa → mmHg) |\n| pO2_Arterial | kPa | `× 7.5006` (kPa → mmHg) |\n| Lactate | mg\u002FdL | `× 0.111` (mg\u002FdL → mmol\u002FL) *(MW≈90.08)* |\n\n#### 2B) Conversion logic\n\nAlgorithm:\n1. If value is within expected range → keep.\n2. If outside range → try each conversion factor for that column.\n3. If a converted value lands within range → accept it.\n4. If none work → **flag** the value for review. If the task\u002Fevaluation requires all values in range, you must take a deterministic action (typically drop those rows, since they cannot be reliably harmonized).\n\n```python\ndef in_range(x, lo, hi, eps=0.0):\n    return (lo - eps) \u003C= x \u003C= (hi + eps)\n\ndef convert_unit_if_needed(value, column, reference_ranges, conversion_factors):\n    \"\"\"Try conversions when out of range; otherwise return as-is.\"\"\"\n    if pd.isna(value) or column not in reference_ranges:\n        return value, False  # (value, was_converted)\n\n    lo, hi = reference_ranges[column]\n\n    if in_range(value, lo, hi):\n        return value, False\n\n    for factor in conversion_factors.get(column, []):\n        converted = value * factor\n        if in_range(converted, lo, hi):\n            return converted, True\n\n    return value, False\n\n# Example application pattern\nrange_errors = []\nfor col in numeric_cols:\n    if col not in reference_ranges:\n        continue\n    lo, hi = reference_ranges[col]\n    new_vals = []\n    for i, x in enumerate(df[col].values):\n        y, _ = convert_unit_if_needed(x, col, reference_ranges, conversion_factors)\n        new_vals.append(y)\n        if pd.notna(y) and not in_range(y, lo, hi):\n            range_errors.append((i, col, y))\n    df[col] = new_vals\n\n# If you must guarantee all values are within range, drop irreconcilable rows\n# (preferred over clamping, because clamping fabricates measurements)\nif range_errors:\n    bad_rows = sorted({i for (i, col, y) in range_errors})\n    df = df.drop(index=bad_rows).reset_index(drop=True)\n```\n\n**Important**:\n- Prefer **dropping rows** that still violate physiologic ranges after trying plausible conversions. This is safer than clamping and matches the task framing (“cannot be recovered or harmonized”).\n- Do **not** silently widen ranges to “make tests pass”; fix the unit assumption\u002Fconversion.\n\n**Examples**:\n\n- Serum Creatinine (µmol\u002FL → mg\u002FdL):\n  - Expected range: 0.2 – 20.0 mg\u002FdL\n  - If value = 673.4 → 673.4 × 0.0113 = 7.61 mg\u002FdL ✓\n\n- Hemoglobin (g\u002FL → g\u002FdL):\n  - Expected range: 3.0 – 20.0 g\u002FdL\n  - If value = 107.5 → 107.5 × 0.1 = 10.75 g\u002FdL ✓\n\n- Blood gas pressures (kPa → mmHg):\n  - pCO2 expected 15–100 mmHg; if value = 5.2 (kPa) → 5.2 × 7.5006 = 39.0 mmHg ✓\n\n- Troponin (ng\u002FL → ng\u002FmL):\n  - Troponin_T expected 0–10 ng\u002FmL; if value = 4650 (ng\u002FL) → 4.65 ng\u002FmL ✓\n\n### Step 3: Format Output (2 Decimal Places)\n\nFormat all values to exactly 2 decimal places (standard precision for clinical lab results):\n\n```python\nfor col in numeric_cols:\n    df[col] = df[col].apply(lambda x: f\"{x:.2f}\" if pd.notna(x) else '')\n```\n\nThis produces clean output like `12.34`, `0.50`, `1234.00`.\n\n## Complete Feature Reference\n\nIf you have a project-provided feature dictionary (ranges + conversions), use it.\n\nIf not, implement a **local mapping** at minimum for:\n- Creatinine (serum + urine)\n- BUN\n- Calcium (total and ionized)\n- Hemoglobin\n- Lipids (cholesterol fractions + triglycerides)\n- Troponins\n- Blood gases (pCO2\u002FpO2)\n- Lactate\n- Vitamin D (25-OH and 1,25-OH)\n- Ferritin \u002F prealbumin\n- Urine protein\n\nThis ensures the range-based conversion strategy has enough information to succeed.\n\n### Feature Categories\n\n| Category | Count | Examples |\n|----------|-------|----------|\n| Kidney Function | 5 | Serum_Creatinine, BUN, eGFR, Cystatin_C |\n| Electrolytes | 6 | Sodium, Potassium, Chloride, Bicarbonate |\n| Mineral & Bone | 7 | Serum_Calcium, Phosphorus, Intact_PTH, Vitamin_D |\n| Hematology\u002FCBC | 5 | Hemoglobin, Hematocrit, RBC_Count, WBC_Count |\n| Iron Studies | 5 | Serum_Iron, TIBC, Ferritin, Transferrin_Saturation |\n| Liver Function | 2 | Total_Bilirubin, Direct_Bilirubin |\n| Proteins\u002FNutrition | 4 | Albumin_Serum, Total_Protein, Prealbumin, CRP |\n| Lipid Panel | 5 | Total_Cholesterol, LDL, HDL, Triglycerides |\n| Glucose Metabolism | 3 | Glucose, HbA1c, Fructosamine |\n| Uric Acid | 1 | Uric_Acid |\n| Urinalysis | 7 | Urine_Albumin, UACR, UPCR, Urine_pH |\n| Cardiac Markers | 4 | BNP, NT_proBNP, Troponin_I, Troponin_T |\n| Thyroid Function | 2 | Free_T4, Free_T3 |\n| Blood Gases | 4 | pH_Arterial, pCO2, pO2, Lactate |\n| Dialysis-Specific | 2 | Beta2_Microglobulin, Aluminum |\n\n## Best Practices\n\n1. **Parse formats first**: Always clean up scientific notation and comma\u002Fdot formats before attempting unit conversion.\n2. **Disambiguate commas**: If both `,` and `.` appear, treat comma as thousands separator; otherwise treat comma as decimal.\n3. **Use range-based detection**: Values outside expected ranges likely need unit conversion.\n4. **Try all plausible conversions** for that analyte (some have 3+ alternate units).\n5. **Do not fabricate values**: Avoid clamping as a primary strategy; instead, drop rows that remain out-of-range after plausible conversions.\n6. **Validate results**: After harmonization, confirm **all required analytes** are within expected physiological ranges.\n7. **Round to 2 decimals**: Output must be exact `X.XX` strings with no scientific notation, commas, or whitespace.\n\n## Additional Resources\n\n- [KDIGO Guidelines](https:\u002F\u002Fkdigo.org\u002F): Clinical guidelines for CKD management\n- [UCUM](https:\u002F\u002Fucum.org\u002F): Unified Code for Units of Measure standard\n","# Lab Unit Harmonization\n\n## Overview\n\nLab Unit Harmonization provides techniques and references for standardizing clinical laboratory data from multiple sources. Real-world healthcare data often contains measurements in different units, varying decimal and numeric formats, and data entry inconsistencies that must be resolved before analysis.\n\nThis skill covers:\n- **Unit Conversion**: Converting between US conventional and SI units\n- **Format Standardization**: Handling scientific notation, decimal formats, whitespace\n- **Data Quality Assessment**: Identifying and quantifying data issues\n- **CKD-Specific Labs**: Practical references for chronic kidney disease-related lab features\n\n## When to Use This Skill\n\nUse this skill when:\n- Harmonizing lab values from multiple hospitals or health systems\n- Converting between US conventional and SI units (e.g., mg\u002FdL to µmol\u002FL)\n- Merging data from EHRs using different default unit conventions\n- Integrating international datasets with mixed unit systems\n- Standardizing inconsistent numeric formats (scientific notation, decimals)\n- Cleaning whitespace, thousand separators, or European decimal formats\n- Validating lab values against expected clinical ranges\n- Preparing CKD lab panels for eGFR calculations or staging models\n- Building ETL pipelines for clinical data warehouses\n- Preprocessing lab data for machine learning models\n\n## Data Quality Issues Reference\n\nReal-world clinical lab data contains multiple types of quality issues. The following table summarizes common issues and their typical prevalence in multi-source datasets:\n\n| Issue Type | Description | Typical Prevalence | Example |\n|------------|-------------|-------------------|---------|\n| **Incomplete Records** | Rows with excessive missing values | 1-5% | Patient record with only 3\u002F62 labs measured |\n| **Mixed Units** | Same analyte reported in different units | 20-40% | Creatinine: mg\u002FdL vs µmol\u002FL |\n| **Scientific Notation** | Large\u002Fsmall values in exponential format | 15-30% | `1.5e3` instead of `1500` |\n| **Thousand Separators** | Commas in large numbers | 10-25% | `1,234.5` vs `1234.5` |\n| **European Decimals** | Comma as decimal separator | 10-20% | `12,5` instead of `12.5` |\n| **Whitespace Issues** | Leading\u002Ftrailing spaces, tabs | 15-25% | `  45.2 ` vs `45.2` |\n| **Missing Values** | Empty, NULL, or sentinel values | Variable | `NaN`, `-999`, blank |\n\n### Features with Multiple Alternative Units\n\nSome features have more than two possible unit representations:\n\n**Three-Unit Features (8 total):**\n| Feature | Unit 1 | Unit 2 | Unit 3 |\n|---------|--------|--------|--------|\n| Magnesium | mg\u002FdL | mmol\u002FL | mEq\u002FL |\n| Serum_Calcium | mg\u002FdL | mmol\u002FL | mEq\u002FL |\n| Hemoglobin | g\u002FdL | g\u002FL | mmol\u002FL |\n| Ferritin | ng\u002FmL | µg\u002FL | pmol\u002FL |\n| Prealbumin | mg\u002FdL | mg\u002FL | g\u002FL |\n| Urine_Creatinine | mg\u002FdL | µmol\u002FL | mmol\u002FL |\n| Troponin_I | ng\u002FmL | µg\u002FL | ng\u002FL |\n| Troponin_T | ng\u002FmL | µg\u002FL | ng\u002FL |\n\n## Core Workflow\n\nThe harmonization process follows these steps in order:\n\n### Step 0: Filter Incomplete Records (Preprocessing)\n\nBefore harmonization, filter out rows with any missing values:\n\n```python\ndef count_missing(row, numeric_cols):\n    \"\"\"Count missing\u002Fempty values in numeric columns\"\"\"\n    count = 0\n    for col in numeric_cols:\n        val = row[col]\n        if pd.isna(val) or str(val).strip() in ['', 'NaN', 'None', 'nan', 'none']:\n            count += 1\n    return count\n\n# Keep only rows with NO missing values\nmissing_counts = df.apply(lambda row: count_missing(row, numeric_cols), axis=1)\ncomplete_mask = missing_counts == 0\ndf = df[complete_mask].reset_index(drop=True)\n```\n\n**Rationale**: Clinical datasets often contain incomplete records (e.g., partial lab panels, cancelled orders, data entry errors). For harmonization tasks, only complete records with all features measured can be reliably processed. Rows with any missing values should be excluded to ensure consistent output quality.\n\n### Step 1: Parse Numeric Formats\n\nParse all raw values to clean floats. In mixed-source lab data you must handle both **European decimal commas** and **thousand separators**.\n\n**Parsing rules (robust + transferable):**\n1. Strip whitespace.\n2. If both `,` and `.` appear, treat `,` as a **thousand separator** and remove it (e.g., `\"1,234.5\" → \"1234.5\"`).\n3. Else if only `,` appears, treat it as a **decimal separator** (e.g., `\"12,34\" → \"12.34\"`).\n4. Then parse with `float()` (this also handles scientific notation like `1.23e2`).\n\n```python\nimport pandas as pd\nimport numpy as np\nimport re\n\n_MISSING = {'', 'nan','NaN','None','NULL','null','NA','N\u002FA'}\n_KEEP_NUM = re.compile(r'[^0-9eE+\\-\\.,]')\n\ndef parse_value(value):\n    \"\"\"Parse a raw value to float with comma\u002Fdot disambiguation.\"\"\"\n    if pd.isna(value):\n        return np.nan\n\n    s = str(value).strip()\n    if s in _MISSING or s.lower() == 'nan':\n        return np.nan\n\n    # Remove stray unit symbols or other junk while keeping numeric structure\n    s = _KEEP_NUM.sub('', s)\n\n    # Disambiguate comma\n    if ',' in s and '.' in s:\n        # comma is thousands separator\n        s = s.replace(',', '')\n    elif ',' in s:\n        # comma is decimal separator\n        s = s.replace(',', '.')\n\n    try:\n        return float(s)\n    except ValueError:\n        return np.nan\n\nfor col in numeric_cols:\n    df[col] = df[col].apply(parse_value)\n```\n\n### Step 2: Unit Conversion (Range-Based Detection)\n\n**Key Principle**: If a value falls outside the expected physiological range in **US conventional** units, it may need unit conversion.\n\nHowever, range-based detection only works if you supply (1) correct target ranges and (2) plausible alternate-unit conversions for that analyte.\n\n#### 2A) Provide target ranges (US conventional) and plausible alternate conversions\n\nIf you do not have an external reference file available at runtime, use an internal mapping for the features you are harmonizing.\n\nBelow is a **minimal, high-impact CKD panel mapping** covering analytes that commonly appear in mixed units and that frequently break downstream range checks if mishandled.\n\n> Notes:\n> - These are intended as *physiologic plausibility windows* for harmonization, not clinical decision limits.\n> - Some analytes (e.g., urine protein) have very wide plausible ranges; conversions are still needed because unit mixes can be orders of magnitude.\n\n**Target ranges (US conventional) used for harmonization checks:**\n\n| Feature | Target unit | Expected physiological range |\n|---|---:|---:|\n| BUN | mg\u002FdL | 5 – 200 |\n| Serum_Calcium (total) | mg\u002FdL | 5 – 15 |\n| Ionized_Calcium | mmol\u002FL | 0.8 – 2.0 |\n| Intact_PTH | pg\u002FmL | 5 – 2500 |\n| Vitamin_D_1_25OH | pg\u002FmL | 5 – 100 |\n| Hemoglobin | g\u002FdL | 3 – 20 |\n| Ferritin | ng\u002FmL (≈ µg\u002FL) | 5 – 5000 |\n| Prealbumin | mg\u002FdL | 5 – 50 |\n| Triglycerides | mg\u002FdL | 30 – 2000 |\n| Urine_Creatinine | mg\u002FdL | 10 – 500 |\n| Urine_Protein | mg\u002FL | 0 – 3000 |\n| Troponin_I | ng\u002FmL | 0 – 50 |\n| Troponin_T | ng\u002FmL | 0 – 10 |\n| pCO2_Arterial | mmHg | 15 – 100 |\n| pO2_Arterial | mmHg | 30 – 500 |\n| Lactate | mmol\u002FL | 0.3 – 20 |\n\n**Common alternate units and conversion factors** (multiply by factor to reach target unit):\n\n| Feature | Alternate unit(s) commonly seen | Convert to target (multiply) |\n|---|---|---:|\n| BUN | mmol\u002FL (urea nitrogen) | `× 2.801` (mmol\u002FL → mg\u002FdL) |\n| Serum_Calcium | mmol\u002FL | `× 4.0` (mmol\u002FL → mg\u002FdL) |\n| Ionized_Calcium | mg\u002FdL | `× 0.2495` (mg\u002FdL → mmol\u002FL) |\n| Intact_PTH | pmol\u002FL | `× 9.43` (pmol\u002FL → pg\u002FmL) *(assay-dependent; use as plausibility conversion)* |\n| Vitamin_D_1_25OH | pmol\u002FL | `× 0.4167` (pmol\u002FL → pg\u002FmL) *(approx; use for harmonization plausibility)* |\n| Hemoglobin | g\u002FL | `× 0.1` (g\u002FL → g\u002FdL) |\n| Ferritin | pmol\u002FL | `× 0.445` (pmol\u002FL → ng\u002FmL) *(approx; plausibility conversion)* |\n| Prealbumin | g\u002FL | `× 100.0` (g\u002FL → mg\u002FdL) |\n| Triglycerides | mmol\u002FL | `× 88.57` (mmol\u002FL → mg\u002FdL) |\n| Urine_Creatinine | µmol\u002FL | `× 0.0113` (µmol\u002FL → mg\u002FdL) |\n| Urine_Creatinine | mmol\u002FL | `× 113.0` (mmol\u002FL → mg\u002FdL) |\n| Urine_Protein | mg\u002FdL | `× 10.0` (mg\u002FdL → mg\u002FL) |\n| Urine_Protein | g\u002FL | `× 1000.0` (g\u002FL → mg\u002FL) |\n| Troponin_I | ng\u002FL | `× 0.001` (ng\u002FL → ng\u002FmL) |\n| Troponin_T | ng\u002FL | `× 0.001` (ng\u002FL → ng\u002FmL) |\n| pCO2_Arterial | kPa | `× 7.5006` (kPa → mmHg) |\n| pO2_Arterial | kPa | `× 7.5006` (kPa → mmHg) |\n| Lactate | mg\u002FdL | `× 0.111` (mg\u002FdL → mmol\u002FL) *(MW≈90.08)* |\n\n#### 2B) Conversion logic\n\nAlgorithm:\n1. If value is within expected range → keep.\n2. If outside range → try each conversion factor for that column.\n3. If a converted value lands within range → accept it.\n4. If none work → **flag** the value for review. If the task\u002Fevaluation requires all values in range, you must take a deterministic action (typically drop those rows, since they cannot be reliably harmonized).\n\n```python\ndef in_range(x, lo, hi, eps=0.0):\n    return (lo - eps) \u003C= x \u003C= (hi + eps)\n\ndef convert_unit_if_needed(value, column, reference_ranges, conversion_factors):\n    \"\"\"Try conversions when out of range; otherwise return as-is.\"\"\"\n    if pd.isna(value) or column not in reference_ranges:\n        return value, False  # (value, was_converted)\n\n    lo, hi = reference_ranges[column]\n\n    if in_range(value, lo, hi):\n        return value, False\n\n    for factor in conversion_factors.get(column, []):\n        converted = value * factor\n        if in_range(converted, lo, hi):\n            return converted, True\n\n    return value, False\n\n# Example application pattern\nrange_errors = []\nfor col in numeric_cols:\n    if col not in reference_ranges:\n        continue\n    lo, hi = reference_ranges[col]\n    new_vals = []\n    for i, x in enumerate(df[col].values):\n        y, _ = convert_unit_if_needed(x, col, reference_ranges, conversion_factors)\n        new_vals.append(y)\n        if pd.notna(y) and not in_range(y, lo, hi):\n            range_errors.append((i, col, y))\n    df[col] = new_vals\n\n# If you must guarantee all values are within range, drop irreconcilable rows\n# (preferred over clamping, because clamping fabricates measurements)\nif range_errors:\n    bad_rows = sorted({i for (i, col, y) in range_errors})\n    df = df.drop(index=bad_rows).reset_index(drop=True)\n```\n\n**Important**:\n- Prefer **dropping rows** that still violate physiologic ranges after trying plausible conversions. This is safer than clamping and matches the task framing (“cannot be recovered or harmonized”).\n- Do **not** silently widen ranges to “make tests pass”; fix the unit assumption\u002Fconversion.\n\n**Examples**:\n\n- Serum Creatinine (µmol\u002FL → mg\u002FdL):\n  - Expected range: 0.2 – 20.0 mg\u002FdL\n  - If value = 673.4 → 673.4 × 0.0113 = 7.61 mg\u002FdL ✓\n\n- Hemoglobin (g\u002FL → g\u002FdL):\n  - Expected range: 3.0 – 20.0 g\u002FdL\n  - If value = 107.5 → 107.5 × 0.1 = 10.75 g\u002FdL ✓\n\n- Blood gas pressures (kPa → mmHg):\n  - pCO2 expected 15–100 mmHg; if value = 5.2 (kPa) → 5.2 × 7.5006 = 39.0 mmHg ✓\n\n- Troponin (ng\u002FL → ng\u002FmL):\n  - Troponin_T expected 0–10 ng\u002FmL; if value = 4650 (ng\u002FL) → 4.65 ng\u002FmL ✓\n\n### Step 3: Format Output (2 Decimal Places)\n\nFormat all values to exactly 2 decimal places (standard precision for clinical lab results):\n\n```python\nfor col in numeric_cols:\n    df[col] = df[col].apply(lambda x: f\"{x:.2f}\" if pd.notna(x) else '')\n```\n\nThis produces clean output like `12.34`, `0.50`, `1234.00`.\n\n## Complete Feature Reference\n\nIf you have a project-provided feature dictionary (ranges + conversions), use it.\n\nIf not, implement a **local mapping** at minimum for:\n- Creatinine (serum + urine)\n- BUN\n- Calcium (total and ionized)\n- Hemoglobin\n- Lipids (cholesterol fractions + triglycerides)\n- Troponins\n- Blood gases (pCO2\u002FpO2)\n- Lactate\n- Vitamin D (25-OH and 1,25-OH)\n- Ferritin \u002F prealbumin\n- Urine protein\n\nThis ensures the range-based conversion strategy has enough information to succeed.\n\n### Feature Categories\n\n| Category | Count | Examples |\n|----------|-------|----------|\n| Kidney Function | 5 | Serum_Creatinine, BUN, eGFR, Cystatin_C |\n| Electrolytes | 6 | Sodium, Potassium, Chloride, Bicarbonate |\n| Mineral & Bone | 7 | Serum_Calcium, Phosphorus, Intact_PTH, Vitamin_D |\n| Hematology\u002FCBC | 5 | Hemoglobin, Hematocrit, RBC_Count, WBC_Count |\n| Iron Studies | 5 | Serum_Iron, TIBC, Ferritin, Transferrin_Saturation |\n| Liver Function | 2 | Total_Bilirubin, Direct_Bilirubin |\n| Proteins\u002FNutrition | 4 | Albumin_Serum, Total_Protein, Prealbumin, CRP |\n| Lipid Panel | 5 | Total_Cholesterol, LDL, HDL, Triglycerides |\n| Glucose Metabolism | 3 | Glucose, HbA1c, Fructosamine |\n| Uric Acid | 1 | Uric_Acid |\n| Urinalysis | 7 | Urine_Albumin, UACR, UPCR, Urine_pH |\n| Cardiac Markers | 4 | BNP, NT_proBNP, Troponin_I, Troponin_T |\n| Thyroid Function | 2 | Free_T4, Free_T3 |\n| Blood Gases | 4 | pH_Arterial, pCO2, pO2, Lactate |\n| Dialysis-Specific | 2 | Beta2_Microglobulin, Aluminum |\n\n## Best Practices\n\n1. **Parse formats first**: Always clean up scientific notation and comma\u002Fdot formats before attempting unit conversion.\n2. **Disambiguate commas**: If both `,` and `.` appear, treat comma as thousands separator; otherwise treat comma as decimal.\n3. **Use range-based detection**: Values outside expected ranges likely need unit conversion.\n4. **Try all plausible conversions** for that analyte (some have 3+ alternate units).\n5. **Do not fabricate values**: Avoid clamping as a primary strategy; instead, drop rows that remain out-of-range after plausible conversions.\n6. **Validate results**: After harmonization, confirm **all required analytes** are within expected physiological ranges.\n7. **Round to 2 decimals**: Output must be exact `X.XX` strings with no scientific notation, commas, or whitespace.\n\n## Additional Resources\n\n- [KDIGO Guidelines](https:\u002F\u002Fkdigo.org\u002F): Clinical guidelines for CKD management\n- [UCUM](https:\u002F\u002Fucum.org\u002F): Unified Code for Units of Measure standard\n",{"name":5,"description":7},"main","cdcb6d230f3b15c3c33f8a2bdd16439f43602cbe","evaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Flab-unit-harmonization\u002Frepaired_run\u002Finputs\u002Fskills\u002Flab-unit-harmonization",1,"https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark","https:\u002F\u002Fgithub.com\u002Flinyouxue","2026-11-14 20:28:35",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add linyouxue\u002Fskill-repair-benchmark --skill lab-unit-harmonization",{"tool":37,"command":38},"bunx","bunx skills add linyouxue\u002Fskill-repair-benchmark --skill lab-unit-harmonization",{"tool":40,"command":41},"pnpm","pnpm dlx skills add linyouxue\u002Fskill-repair-benchmark --skill lab-unit-harmonization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Flab-unit-harmonization\u002Frepaired_run\u002Finputs\u002Fskills\u002Flab-unit-harmonization\u002FSKILL.md",true,[45],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"reference\u002Fckd_lab_features.md","REFERENCE","参考文档",12949,"https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Flab-unit-harmonization\u002Frepaired_run\u002Finputs\u002Fskills\u002Flab-unit-harmonization\u002Freference\u002Fckd_lab_features.md",[52,59,66,73,78,83],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M7E1HGVRY73NBJ022CJG13X6","video-frame-extraction","Extract frames from video files and save them as images using OpenCV","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M7E1HAG5R7CJ9C8NYJS771MB","openai-vision","Analyze images and multi-frame sequences using OpenAI GPT vision models","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M7E1H7DADKB6QBWKC2KQ63SZ","image-ocr","Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[],{"skillNo":74,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7E1H0WBNT43TENGQY7AVZHD","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":79,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7E1GTC7D4N4Q2EF03875J9E","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":84,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M7E1GQ92CWFMGH53KSSE4WER","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[]]