Skip to content

Commit

Permalink
Replace invocations of some deprecated Hail functions with their repl…
Browse files Browse the repository at this point in the history
…acements [minor] (hail-is#13349)

Rewrite invocations of `hl.cond()` to `hl.if_else()`, `hl.null()` to
`hl.missing()`, and `hl.zip_with_index()` to `hl.enumerate()`.

Very minor, but a few of these appear in our test logs (and probably
yours as well), which makes for noise when you're tracking down other
problems in the logs:

```
hail/methods/misc.py:437: DeprecationWarning: Call to deprecated function (or staticmethod) cond. (Replaced by hl.if_else) -- Deprecated since version 0.2.59.
hail/vds/methods.py:79: DeprecationWarning: Call to deprecated function (or staticmethod) zip_with_index. (Replaced by hl.enumerate) -- Deprecated since version 0.2.56.
hail/vds/methods.py:75: DeprecationWarning: Call to deprecated function (or staticmethod) null. (Replaced by hl.missing) -- Deprecated since version 0.2.62.
```
  • Loading branch information
jmarshall authored Aug 3, 2023
1 parent 8421b18 commit 6921e6c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def large_range_matrix_table_sum():
@benchmark(args=profile_25.handle('mt'))
def kyle_sex_specific_qc(mt_path):
mt = hl.read_matrix_table(mt_path)
mt = mt.annotate_cols(sex=hl.cond(hl.rand_bool(0.5), 'Male', 'Female'))
mt = mt.annotate_cols(sex=hl.if_else(hl.rand_bool(0.5), 'Male', 'Female'))
(num_males, num_females) = mt.aggregate_cols((hl.agg.count_where(mt.sex == 'Male'),
hl.agg.count_where(mt.sex == 'Female')))
mt = mt.annotate_rows(
Expand Down
6 changes: 3 additions & 3 deletions datasets/load/load.1000_Genomes_phase3_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
ht_relationships['paternal_id']),
maternal_id=hl.or_missing(ht_relationships['maternal_id'] != '0',
ht_relationships['maternal_id']),
relationship_role=hl.cond(ht_relationships['relationship_role'] == 'unrel',
'unrelated',
ht_relationships['relationship_role']),
relationship_role=hl.if_else(ht_relationships['relationship_role'] == 'unrel',
'unrelated',
ht_relationships['relationship_role']),
sibling_ids=hl.or_missing(ht_relationships['sibling_ids'] == '0',
hl.map(lambda x: x.strip(), ht_relationships['sibling_ids'].split(','))),
children_ids=hl.or_missing(ht_relationships['children_ids'] == '0',
Expand Down
2 changes: 1 addition & 1 deletion datasets/load/load.DANN.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ht = ht.select('score')

ht = ht.annotate_globals(metadata=hl.struct(name=name,
version=hl.null(hl.tstr),
version=hl.missing(hl.tstr),
reference_genome=build,
n_rows=n_rows,
n_partitions=n_partitions))
Expand Down
2 changes: 1 addition & 1 deletion datasets/load/load.GTEx_v7_RNA_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.when(ht_subjects['DTHHRDY'] == '2', '2_fast_death_of_natural_causes')
.when(ht_subjects['DTHHRDY'] == '3', '3_intermediate_death')
.when(ht_subjects['DTHHRDY'] == '4', '4_slow_death')
.default(hl.null(hl.tstr))))
.default(hl.missing(hl.tstr))))
ht_subjects = ht_subjects.select('is_female', 'age_range', 'death_classification_hardy_scale')
ht_subjects.write('hdfs:///tmp/subjects.ht', overwrite=True)
ht_subjects = hl.read_table('hdfs:///tmp/subjects.ht')
Expand Down
2 changes: 1 addition & 1 deletion datasets/load/load.LDSC_baseline_v1.1_bed_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def locus_interval_expr(contig, start, end, includes_start, includes_end,
ht = ht.annotate(interval=hl.locus_interval(
contig=ht.f0.replace('chr', ''),
start=ht.f1 + 1,
end=hl.cond(end > length, length, end)),
end=hl.if_else(end > length, length, end)),
includes_start=True,
includes_end=True,
reference_genome='GRCh37'))
Expand Down
2 changes: 1 addition & 1 deletion hail/python/hail/methods/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def segment_intervals(ht, points):
lower = hl.if_else((lower < n_points) & (points[lower] == interval.start), lower + 1, lower)
higher = hl.if_else((higher < n_points) & (points[higher] == interval.end), higher - 1, higher)
interval_results = hl.rbind(lower, higher,
lambda lower, higher: hl.cond(
lambda lower, higher: hl.if_else(
lower >= higher,
[interval],
hl.flatten([
Expand Down
6 changes: 3 additions & 3 deletions hail/python/hail/vds/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def coalesce_join(ref, var):
return hl.if_else(hl.is_defined(var),
var.select(*shared_fields, *var_fields),
ref.annotate(**{call_field: hl.call(0, 0)})
.select(*shared_fields, **{f: hl.null(var[f].dtype) for f in var_fields}))
.select(*shared_fields, **{f: hl.missing(var[f].dtype) for f in var_fields}))

dr = dr.annotate(
_dense=hl.rbind(dr._ref_entries,
lambda refs_at_this_row: hl.zip_with_index(hl.zip(dr._var_entries, dr.dense_ref)).map(
lambda refs_at_this_row: hl.enumerate(hl.zip(dr._var_entries, dr.dense_ref)).map(
lambda tup: coalesce_join(hl.coalesce(refs_at_this_row[tup[0]],
hl.or_missing(tup[1][1]._END_GLOBAL >= dr.locus.global_position(),
tup[1][1])), tup[1][0])
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def keep_last(t1, t2):
t2)

# approximate a scan that merges before result
ht = ht.annotate(prev_block=hl.zip(hl.scan.array_agg(lambda elt: hl.scan.fold((hl.null(rd.entry.dtype), False),
ht = ht.annotate(prev_block=hl.zip(hl.scan.array_agg(lambda elt: hl.scan.fold((hl.missing(rd.entry.dtype), False),
lambda acc: keep_last(acc, (
elt, False)),
keep_last), ht.entries), ht.entries)
Expand Down

0 comments on commit 6921e6c

Please sign in to comment.