From 6921e6c138e3f67600fdcf3df482f9b1eaf91b6b Mon Sep 17 00:00:00 2001 From: John Marshall Date: Fri, 4 Aug 2023 03:48:49 +1200 Subject: [PATCH] Replace invocations of some deprecated Hail functions with their replacements [minor] (#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. ``` --- .../python/benchmark_hail/run/matrix_table_benchmarks.py | 2 +- datasets/load/load.1000_Genomes_phase3_relationships.py | 6 +++--- datasets/load/load.DANN.py | 2 +- datasets/load/load.GTEx_v7_RNA_seq.py | 2 +- datasets/load/load.LDSC_baseline_v1.1_bed_files.py | 2 +- hail/python/hail/methods/misc.py | 2 +- hail/python/hail/vds/methods.py | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/benchmark/python/benchmark_hail/run/matrix_table_benchmarks.py b/benchmark/python/benchmark_hail/run/matrix_table_benchmarks.py index b5df2630a4b..85dfdb3b9c5 100644 --- a/benchmark/python/benchmark_hail/run/matrix_table_benchmarks.py +++ b/benchmark/python/benchmark_hail/run/matrix_table_benchmarks.py @@ -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( diff --git a/datasets/load/load.1000_Genomes_phase3_relationships.py b/datasets/load/load.1000_Genomes_phase3_relationships.py index 666d1fca885..9a7dff4595d 100644 --- a/datasets/load/load.1000_Genomes_phase3_relationships.py +++ b/datasets/load/load.1000_Genomes_phase3_relationships.py @@ -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', diff --git a/datasets/load/load.DANN.py b/datasets/load/load.DANN.py index 026127dcf16..59087718df0 100644 --- a/datasets/load/load.DANN.py +++ b/datasets/load/load.DANN.py @@ -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)) diff --git a/datasets/load/load.GTEx_v7_RNA_seq.py b/datasets/load/load.GTEx_v7_RNA_seq.py index b1dba968f95..98b1cc1414a 100644 --- a/datasets/load/load.GTEx_v7_RNA_seq.py +++ b/datasets/load/load.GTEx_v7_RNA_seq.py @@ -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') diff --git a/datasets/load/load.LDSC_baseline_v1.1_bed_files.py b/datasets/load/load.LDSC_baseline_v1.1_bed_files.py index 5df094df5c7..7e4f7e49c3e 100644 --- a/datasets/load/load.LDSC_baseline_v1.1_bed_files.py +++ b/datasets/load/load.LDSC_baseline_v1.1_bed_files.py @@ -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')) diff --git a/hail/python/hail/methods/misc.py b/hail/python/hail/methods/misc.py index a74bc04d089..819d335bdde 100644 --- a/hail/python/hail/methods/misc.py +++ b/hail/python/hail/methods/misc.py @@ -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([ diff --git a/hail/python/hail/vds/methods.py b/hail/python/hail/vds/methods.py index c80c950a00a..320de78c0d6 100644 --- a/hail/python/hail/vds/methods.py +++ b/hail/python/hail/vds/methods.py @@ -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]) @@ -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)