# Key type mismatch: cannot index table with given expressions

**URL:** <https://discuss.hail.is/t/key-type-mismatch-cannot-index-table-with-given-expressions/3690>\
**Category:** Hail Query & hailctl\
**Created:** [December 20, 2023, 6:05pm UTC](https://discuss.hail.is/t/key-type-mismatch-cannot-index-table-with-given-expressions/3690 "2023-12-20T18:05:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgarcia](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mgarcia](https://discuss.hail.is/u/mgarcia)\
**Post date:** [December 20, 2023, 6:05pm UTC](https://discuss.hail.is/t/key-type-mismatch-cannot-index-table-with-given-expressions/3690/1 "2023-12-20T18:05:44Z")

</div>

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.

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

```

 ![Screenshot 2023-12-20 at 9.44.47 AM](https://canada1.discourse-cdn.com/flex036/uploads/hail/original/2X/5/5d307021769d2770309e66f4dc961b79f66b90ba.png)

```python
    vcf = vcf.annotate_cols(
        sa=samples[vcf.s]
    )

```

```python
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

```

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [January 2, 2024, 2:41pm UTC](https://discuss.hail.is/t/key-type-mismatch-cannot-index-table-with-given-expressions/3690/2 "2024-01-02T14:41:30Z")

</div>

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:

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

```
