Skip to content

fix: raise ValueError on empty CNV HMM data instead of IndexError#1258

Open
ADAMSmugwe wants to merge 1 commit intomalariagen:masterfrom
ADAMSmugwe:fix/cnv-empty-data-index-error
Open

fix: raise ValueError on empty CNV HMM data instead of IndexError#1258
ADAMSmugwe wants to merge 1 commit intomalariagen:masterfrom
ADAMSmugwe:fix/cnv-empty-data-index-error

Conversation

@ADAMSmugwe
Copy link
Copy Markdown

Problem

Two plotting functions in cnv_data.py crash with a cryptic
IndexError: index 0 is out of bounds for axis 0 with size 0
when a requested region or sample has no valid CNV HMM data:

  • plot_cnv_hmm_coverage — after data.query("call_CN >= 0") filters
    out all uncalled windows, accessing values[0] / values[-1] on the
    empty DataFrame crashes.
  • plot_cnv_hmm_heatmap_track — if n_windows == 0 for the requested
    region, accessing start[0] and end[-1] crashes.

Fix

Added an early ValueError guard in both functions before the unsafe
index access, with a descriptive message that names the sample/region
so the user knows exactly what produced no data.

Follows the existing pattern used in frq_base.py and elsewhere in
the codebase.

Files Changed

  • malariagen_data/anoph/cnv_data.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant