Skip to content

Commit daca608

Browse files
authored
bugfix allow fields with periods in name (#1033)
1 parent 6efe964 commit daca608

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

v03_pipeline/lib/misc/nested_field.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33

44
def parse_nested_field(t: hl.MatrixTable | hl.Table, fields: str):
5-
# Grab the field and continually select it from the hail table.
65
expression = t
7-
for field in fields.split('.'):
6+
# Behavior here allows only a single nested field.
7+
# Additional nesting is considered to be part of the
8+
# name of the field. e.g. `gnomadv4.1_AF`.
9+
for field in fields.split('.', maxsplit=1):
810
# Select from multi-allelic list.
911
if field.endswith('#'):
1012
expression = expression[field[:-1]][

v03_pipeline/lib/misc/nested_field_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_parse_nested_field(self):
1818
'alleles': ['A', 'C'],
1919
'a': hl.Struct(d=1),
2020
'b': hl.Struct(e=[2, 9]),
21+
'h': hl.Struct(**{'i.j': 1}),
2122
'a_index': 1,
2223
},
2324
{
@@ -29,6 +30,7 @@ def test_parse_nested_field(self):
2930
'alleles': ['A', 'C'],
3031
'a': hl.Struct(d=3),
3132
'b': hl.Struct(e=[4, 5]),
33+
'h': hl.Struct(**{'i.j': 2}),
3234
'a_index': 1,
3335
},
3436
],
@@ -37,6 +39,7 @@ def test_parse_nested_field(self):
3739
alleles=hl.tarray(hl.tstr),
3840
a=hl.tstruct(d=hl.tint32),
3941
b=hl.tstruct(e=hl.tarray(hl.tint32)),
42+
h=hl.tstruct(**{'i.j': hl.tint32}),
4043
a_index=hl.tint32,
4144
),
4245
key=['locus', 'alleles'],
@@ -45,6 +48,7 @@ def test_parse_nested_field(self):
4548
d=parse_nested_field(ht, 'a.d'),
4649
e=parse_nested_field(ht, 'b.e#'),
4750
f=parse_nested_field(ht, 'a'),
51+
g=parse_nested_field(ht, 'h.i.j'),
4852
)
4953
self.assertListEqual(
5054
ht.collect(),
@@ -59,6 +63,7 @@ def test_parse_nested_field(self):
5963
d=1,
6064
e=2,
6165
f=hl.Struct(d=1),
66+
g=1,
6267
),
6368
hl.Struct(
6469
locus=hl.Locus(
@@ -70,6 +75,7 @@ def test_parse_nested_field(self):
7075
d=3,
7176
e=4,
7277
f=hl.Struct(d=3),
78+
g=2,
7379
),
7480
],
7581
)

0 commit comments

Comments
 (0)