Key type mismatch: cannot index table with given expressions

I am trying to annotate a MatrixTable with sample IDs written as integers, but I am encountering the key type mismatch error below. Is there a way to import the values into samples as strings to avoid this error? Should I use hl.import_lines? Thank you in advance.

    samples = hl.import_table(args.sub_annot, key='SAMPLE', impute=True)

    vcf = vcf.annotate_cols(
        sa=samples[vcf.s]
    )
Traceback (most recent call last):
File "/opt/notebooks/hail_variant_qc_V10.py, line 485, in <module> sa=samples [vcf.s]
File "/opt/conda/lib/python3.9/site-packages/hail/table-py, line 379, in getitem return self.index(*wrap_to_tuple(item))
File "/opt/conda/lib/python3.9/site-packages/hail/table-py", line 1840, in index
raise ExpressionException(f"Key type mismatch: cannot index table with given expressions: \n" hail.expr.expressions.base_expression. ExpressionException: Key type mismatch: cannot index table with given expressions:
Table key:
int32
Index Expressions: str

Hey @mgarcia !

You probably don’t want hl.import_lines. hl.import_table is the recommended way to import delimited text files.

The issue is that Hail is guessing that your TSV/CSV file’s SAMPLE column is an integer (because they’re all parsable as integers), but your matrix table is probably coming from a VCF. hl.import_vcf unconditionally imports sample ids as strings. The fix is simple: hl.import_table accepts a types argument which overrides type imputation for the specified fields:

samples = hl.import_table(..., types={'SAMPLE': hl.tstr})