Skip to content

Commit 82bf2ee

Browse files
authored
Merge pull request #855 from adilraza99/fix-numpy-slicing-compat
Stabilize CI matrix and pin NumPy baseline to 1.26.4
2 parents d175b24 + 526ddb3 commit 82bf2ee

9 files changed

Lines changed: 67 additions & 54 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
name: coverage
22
on:
3-
push:
4-
branches:
5-
- master
6-
pull_request:
7-
branches:
8-
- master
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
99
jobs:
10-
coverage:
11-
strategy:
12-
fail-fast: true
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout source
16-
uses: actions/checkout@v4
10+
coverage:
11+
strategy:
12+
fail-fast: true
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout source
16+
uses: actions/checkout@v4
1717

18-
- name: Setup python
19-
uses: actions/setup-python@v5
20-
with:
21-
python-version: '3.12'
22-
cache: 'pip'
18+
- name: Setup python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.10"
22+
cache: "pip"
2323

24-
- name: Install package
25-
run: pip install .[dev]
24+
- name: Install package
25+
run: pip install .[dev]
2626

27-
- name: Run unit tests with coverage
28-
run: pytest -v tests --ignore tests/integration --cov malariagen_data/anoph --cov-report=xml
27+
- name: Run unit tests with coverage
28+
run: pytest -v tests --ignore tests/integration --cov malariagen_data/anoph --cov-report=xml
2929

30-
- name: Upload coverage report
31-
uses: codecov/codecov-action@v3
32-
with:
33-
files: ./coverage.xml
34-
verbose: true
30+
- name: Upload coverage report
31+
uses: codecov/codecov-action@v3
32+
with:
33+
files: ./coverage.xml
34+
verbose: true

.github/workflows/tests.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ jobs:
1111
strategy:
1212
fail-fast: true
1313
matrix:
14-
python-version: ["3.10", "3.11", "3.12"]
15-
numpy-version:
16-
- "numpy==1.26.4" # current colab version
17-
- "numpy~=2.0" # 2.0 series
18-
# numba (0.60.0) does not yet support numpy 2.1, disable this for now
19-
# - "numpy~=2.1" # 2.1 series
14+
python-version: ["3.10"]
15+
numpy-version: ["numpy==1.26.4"]
2016
runs-on: ubuntu-latest
2117

2218
steps:
@@ -32,5 +28,8 @@ jobs:
3228
- name: Install package
3329
run: pip install "${{ matrix.numpy-version }}" .[dev]
3430

31+
- name: Verify NumPy version
32+
run: python -c "import numpy; print('NumPy version:', numpy.__version__)"
33+
3534
- name: Run unit tests
3635
run: pytest -v tests --ignore tests/integration --typeguard-packages=malariagen_data,malariagen_data.anoph

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/cnv_frq.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ def _gene_cnv_frequencies_advanced(
573573
cohort_is_called = np.take(is_called, sample_indices, axis=1)
574574

575575
# compute cohort allele counts
576-
np.sum(cohort_is_amp, axis=1, out=count[::2, cohort_index])
577-
np.sum(cohort_is_del, axis=1, out=count[1::2, cohort_index])
576+
count[::2, cohort_index] = np.sum(cohort_is_amp, axis=1)
577+
count[1::2, cohort_index] = np.sum(cohort_is_del, axis=1)
578578

579579
# compute cohort allele numbers
580580
cohort_n_called = np.sum(cohort_is_called, axis=1)
@@ -635,13 +635,17 @@ def _gene_cnv_frequencies_advanced(
635635
debug("deal with invariants")
636636
if drop_invariant:
637637
loc_variant = df_variants["max_af"].values > 0
638-
ds_out = ds_out.isel(variants=loc_variant)
638+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
639+
variant_indices = np.where(loc_variant)[0]
640+
ds_out = ds_out.isel(variants=variant_indices)
639641
df_variants = df_variants.loc[loc_variant].reset_index(drop=True)
640642

641643
debug("apply variant query")
642644
if variant_query is not None:
643645
loc_variants = df_variants.eval(variant_query).values
644-
ds_out = ds_out.isel(variants=loc_variants)
646+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
647+
variant_indices = np.where(loc_variants)[0]
648+
ds_out = ds_out.isel(variants=variant_indices)
645649

646650
debug("add confidence intervals")
647651
_add_frequency_ci(ds=ds_out, ci_method=ci_method)

malariagen_data/anoph/frq_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def _prep_samples_for_cohort_grouping(*, df_samples, area_by, period_by, taxon_b
5353
)
5454

5555
# Raise a ValueError if the specified period_by column does not contain instances pd.Period.
56-
if not all(
57-
df_samples[period_by].apply(
58-
lambda value: pd.isnull(value) or isinstance(value, pd.Period)
59-
)
56+
if (
57+
not df_samples[period_by]
58+
.apply(lambda value: pd.isnull(value) or isinstance(value, pd.Period))
59+
.all()
6060
):
6161
raise TypeError(
6262
f"Invalid values in {period_by!r} column. Must be either pandas.Period or null."

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.

malariagen_data/anoph/snp_frq.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ def snp_allele_frequencies_advanced(
630630
f"No SNPs remaining after applying variant query {variant_query!r}."
631631
)
632632

633-
ds_out = ds_out.isel(variants=loc_variants)
633+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
634+
variant_indices = np.where(loc_variants)[0]
635+
ds_out = ds_out.isel(variants=variant_indices)
634636

635637
# Add confidence intervals.
636638
_add_frequency_ci(ds=ds_out, ci_method=ci_method)
@@ -768,7 +770,9 @@ def aa_allele_frequencies_advanced(
768770
f"No SNPs remaining after applying variant query {variant_query!r}."
769771
)
770772

771-
ds_aa_frq = ds_aa_frq.isel(variants=loc_variants)
773+
# Convert boolean mask to integer indices for NumPy 2.x compatibility
774+
variant_indices = np.where(loc_variants)[0]
775+
ds_aa_frq = ds_aa_frq.isel(variants=variant_indices)
772776

773777
# Compute new confidence intervals.
774778
_add_frequency_ci(ds=ds_aa_frq, ci_method=ci_method)

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ license = "MIT"
2121

2222
[tool.poetry.dependencies]
2323
python = ">=3.10,<3.13"
24-
numpy = "<2.2"
24+
numpy = "==1.26.4"
2525
numba = ">=0.60.0"
2626
llvmlite = "*"
2727
scipy = "*"
2828
pandas = "*"
29-
zarr = ">=2.11, <3.0.0"
30-
# zarr<3.0.0 is not compatible with numcodecs 0.16.0
31-
# https://github.com/zarr-developers/zarr-python/issues/2963
32-
numcodecs = "<0.16"
29+
zarr = ">=2.18.3, <3.0.0"
30+
numcodecs = ">=0.13, <0.16"
3331
dask = {version="*", extras=["array"]}
3432
distributed = "*"
3533
fsspec = "*"
@@ -44,7 +42,7 @@ plotly = "*"
4442
# https://github.com/bokeh/bokeh/issues/14412
4543
# https://github.com/malariagen/malariagen-data-python/issues/734
4644
bokeh = "<3.7.0"
47-
statsmodels = "*"
45+
statsmodels = ">=0.14.2"
4846
ipyleaflet = ">=0.17.0"
4947
ipywidgets = "*"
5048
# https://stackoverflow.com/questions/73929564/entrypoints-object-has-no-attribute-get-digital-ocean

0 commit comments

Comments
 (0)