Handle missing array values

I have such code:

hl.struct(**{'AC': nisc[mt.row_key].info.AC[mt.a_index-1],
             'AF': nisc[mt.row_key].info.AF[mt.a_index-1]})

That fails with index out of bounds error if nisc[mt.row_key].info.AC does not have correct length that should be >= mt.a_index. What I need is something like:

nisc_ac = nisc[mt.row_key].info.AC[mt.a_index-1] if hl.len(nisc[mt.row_key].info.AC) >= mt.a_index else null


nisc_ac = hl.if_else(hl.len(nisc[mt.row_key].info.AC) >= mt.a_index, nisc[mt.row_key].info.AC[mt.a_index], hl.missing(hl.tint32))

But none of the two are working. Need a way to handle missing values upon array access, I think.

Your last example should work, but should just be > not >=. You can only index up to length - 1 .

1 Like

Yeah, just off by one error. Thanks a lot!