Skip to content

Commit 0012db6

Browse files
committed
Fix NumPy 2.x boolean indexing in hap_data and cnv_data filters
1 parent 600111e commit 0012db6

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

malariagen_data/anoph/cnv_data.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ def cnv_hmm(
240240
# noinspection PyArgumentList
241241
other = pd.Interval(r.start, r.end, closed="both")
242242
loc_region = index.overlaps(other) # type: ignore
243-
x = x.isel(variants=loc_region)
243+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
244+
variant_indices = np.where(loc_region)[0]
245+
x = x.isel(variants=variant_indices)
244246

245247
lx.append(x)
246248

@@ -267,7 +269,9 @@ def cnv_hmm(
267269
if max_coverage_variance is not None:
268270
cov_var = ds["sample_coverage_variance"].values
269271
loc_pass_samples = cov_var <= max_coverage_variance
270-
ds = ds.isel(samples=loc_pass_samples)
272+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
273+
sample_indices = np.where(loc_pass_samples)[0]
274+
ds = ds.isel(samples=sample_indices)
271275

272276
return ds
273277

@@ -445,7 +449,9 @@ def cnv_coverage_calls(
445449
# noinspection PyArgumentList
446450
other = pd.Interval(r.start, r.end, closed="both")
447451
loc_region = index.overlaps(other) # type: ignore
448-
x = x.isel(variants=loc_region)
452+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
453+
variant_indices = np.where(loc_region)[0]
454+
x = x.isel(variants=variant_indices)
449455

450456
lx.append(x)
451457
ds = _simple_xarray_concat(lx, dim=DIM_VARIANT)

malariagen_data/anoph/hap_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,9 @@ def haplotypes(
416416
raise ValueError(
417417
f"No samples found for phasing analysis {analysis!r} and query {sample_query_prepped!r}"
418418
)
419-
ds = ds.isel(samples=loc_samples)
419+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
420+
sample_indices = np.where(loc_samples)[0]
421+
ds = ds.isel(samples=sample_indices)
420422

421423
if cohort_size is not None:
422424
# Handle cohort size - overrides min and max.

0 commit comments

Comments
 (0)