# \`hl.eval\` errors out on a StringExpression

**URL:** <https://discuss.hail.is/t/hl-eval-errors-out-on-a-stringexpression/3388>\
**Category:** Hail Query & hailctl\
**Created:** [May 16, 2023, 3:06am UTC](https://discuss.hail.is/t/hl-eval-errors-out-on-a-stringexpression/3388 "2023-05-16T03:06:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![faizal\_eeman](https://avatars.discourse-cdn.com/v4/letter/f/dbc845/32.png) [@faizal\_eeman](https://discuss.hail.is/u/faizal_eeman)\
**Post date:** [May 16, 2023, 3:06am UTC](https://discuss.hail.is/t/hl-eval-errors-out-on-a-stringexpression/3388/1 "2023-05-16T03:06:38Z")

</div>

Trying to extract sample ID from a VCF file imported as a matrix table. I did so by accessing the column key,

vcf\_mt = hl.import\_vcf(‘./test.vcf’)  
sample = vcf\_mt.s

I want to use `hl.eval()` on the above variable `sample` but it errors out.

```python
>>> sample
<StringExpression of type str>
>>>
>>> sample.show()
+---------+
| s |
+---------+
| str |
+---------+
| "test" |
+---------+
>>>
>>> hl.eval(sample)
hail.expr.expressions.base_expression.ExpressionException: scope violation: 'eval' expects an expression indexed by []
    Found indices ['column'], with unexpected indices ['column']. Invalid fields:
        's' (indices ['column'])

```

I understand the variable `sample` has an index, but how do I evaluate this StringExpression?

I’m basically trying to parse the sample ID from the matrix table.

Faizal

---

<div class="post-metadata">

**Author:** ![simeoncarstens](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@simeoncarstens](https://discuss.hail.is/u/simeoncarstens)\
**Post date:** [May 16, 2023, 9:34am UTC](https://discuss.hail.is/t/hl-eval-errors-out-on-a-stringexpression/3388/2 "2023-05-16T09:34:48Z")

</div>

Instead of `hl.eval()`, I think you would rather want to use `sample.collect()`, which will give you a list with all the sample IDs.

---

<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:** [May 16, 2023, 2:03pm UTC](https://discuss.hail.is/t/hl-eval-errors-out-on-a-stringexpression/3388/3 "2023-05-16T14:03:40Z")

</div>

@simeoncarstens is right; you basically never want to use `hl.eval` unless you’re playing with expressions e.g.:

```python
x = hl.literal(hl.dict([(1, 'a'), (10, 'b')])
get_one = x[1]
hl.eval(get_one)

```

`x.field.collect()` or `x.aggregate(hl.agg.collect(x.field))` are what you’re looking for.

---

<div class="post-metadata">

**Author:** ![faizal\_eeman](https://avatars.discourse-cdn.com/v4/letter/f/dbc845/32.png) [@faizal\_eeman](https://discuss.hail.is/u/faizal_eeman)\
**Post date:** [May 16, 2023, 5:35pm UTC](https://discuss.hail.is/t/hl-eval-errors-out-on-a-stringexpression/3388/4 "2023-05-16T17:35:25Z")

</div>

`sample.collect()` is exactly what I was looking for.

Thanks for the details on `hl.eval`!
