Skip to content

Commit d9c5c9a

Browse files
committed
Upgrade mypy to latest version. Turn off strict mode.
1 parent 93af9a2 commit d9c5c9a

File tree

10 files changed

+34
-31
lines changed

10 files changed

+34
-31
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ repos:
2222
- id: flake8
2323
language_version: python3
2424
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v0.782
25+
rev: v0.931
2626
hooks:
2727
- id: mypy
28-
args: ["--strict", "--show-error-codes"]
29-
additional_dependencies: ["numpy>=1.21.2", "xarray", "dask[array]", "scipy", "typing-extensions", "zarr", "numba", "dask-ml", "networkx"]
28+
args: ["--show-error-codes", "--ignore-missing-imports"]
29+
additional_dependencies: ["numpy>=1.21.2", "xarray", "dask[array]", "scipy", "typing-extensions", "zarr", "numba", "dask-ml", "networkx", "types-PyYAML"]

sgkit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pkg_resources import DistributionNotFound, get_distribution
1+
from pkg_resources import DistributionNotFound, get_distribution # type: ignore[import]
22

33
from .display import display_genotypes
44
from .distance.api import pairwise_distance

sgkit/io/bgen/bgen_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __getitem__(self, idx: Any) -> NDArray:
145145
res = np.zeros((len(all_vaddr), len(probs), 3), dtype=self.dtype)
146146
res[i] = probs
147147
res = res[..., idx[2]] # type: ignore[index]
148-
return np.squeeze(res, axis=squeeze_dims)
148+
return np.squeeze(res, axis=squeeze_dims) # type: ignore[arg-type]
149149

150150

151151
def _split_alleles(allele_ids: bytes) -> List[bytes]:
@@ -520,7 +520,7 @@ def rechunk_bgen(
520520

521521
zarr.consolidate_metadata(output)
522522

523-
ds: Dataset = xr.open_zarr(output, concat_characters=False) # type: ignore[no-untyped-call]
523+
ds = xr.open_zarr(output, concat_characters=False) # type: ignore[no-untyped-call]
524524
if pack:
525525
ds = unpack_variables(ds)
526526

sgkit/io/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def _slice_zarrs(
132132
) -> ArrayLike:
133133
"""Slice concatenated zarrs by locs"""
134134
# convert array locations to slices
135-
locs = [slice(*loc) for loc in locs]
135+
locs = [slice(*loc) for loc in locs] # type: ignore[misc]
136136
# determine which zarr files are needed
137-
start, stop = locs[0].start, locs[0].stop # stack on first axis
137+
start, stop = locs[0].start, locs[0].stop # type: ignore[attr-defined] # stack on first axis
138138
i0 = _zarr_index(offsets, start)
139139
i1 = _zarr_index(offsets, stop)
140140
if i0 == i1: # within a single zarr file

sgkit/stats/pca.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ def pca_stats(ds: Dataset, est: BaseEstimator, *, merge: bool = True) -> Dataset
126126
_get(est, "explained_variance_ratio_"),
127127
),
128128
}
129-
new_ds = Dataset({k: v for k, v in new_ds.items() if v[1] is not None})
129+
new_ds = Dataset({k: v for k, v in new_ds.items() if v[1] is not None}) # type: ignore[assignment]
130130
if "sample_pca_component" in new_ds and "sample_pca_explained_variance" in new_ds:
131131
new_ds[variables.sample_pca_loading] = new_ds[
132132
variables.sample_pca_component
133-
] * np.sqrt(new_ds[variables.sample_pca_explained_variance].data)
134-
return conditional_merge_datasets(ds, variables.validate(new_ds), merge)
133+
] * np.sqrt(
134+
new_ds[variables.sample_pca_explained_variance].data # type: ignore[attr-defined]
135+
)
136+
return conditional_merge_datasets(ds, variables.validate(new_ds), merge) # type: ignore[call-overload]
135137

136138

137139
def pca(

sgkit/stats/popgen.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def divergence(
265265
n_variants = ds.dims["variants"]
266266
n_cohorts = ds.dims["cohorts"]
267267
ac = da.asarray(ac)
268-
shape = (ac.chunks[0], n_cohorts, n_cohorts)
268+
shape = (ac.chunks[0], n_cohorts, n_cohorts) # type: ignore[index]
269269
d = da.map_blocks(_divergence, ac, chunks=shape, dtype=np.float64)
270270
assert_array_shape(d, n_variants, n_cohorts, n_cohorts)
271271

@@ -741,7 +741,7 @@ def pbs(
741741

742742
# calculate PBS triples
743743
t = da.asarray(t)
744-
shape = (t.chunks[0], n_cohorts, n_cohorts, n_cohorts)
744+
shape = (t.chunks[0], n_cohorts, n_cohorts, n_cohorts) # type: ignore[attr-defined]
745745

746746
cohorts = cohorts or list(itertools.combinations(range(n_cohorts), 3)) # type: ignore
747747
ct = _cohorts_to_array(cohorts, ds.indexes.get("cohorts_0", None))
@@ -763,23 +763,23 @@ def pbs(
763763
def _Garud_h(haplotypes: ArrayLike) -> ArrayLike:
764764
# find haplotype counts (sorted in descending order)
765765
counts = sorted(collections.Counter(haplotypes.tolist()).values(), reverse=True)
766-
counts = np.array(counts)
766+
counts = np.array(counts) # type: ignore[assignment]
767767

768768
# find haplotype frequencies
769769
n = haplotypes.shape[0]
770-
f = counts / n
770+
f = counts / n # type: ignore[operator]
771771

772772
# compute H1
773773
h1 = np.sum(f ** 2)
774774

775775
# compute H12
776-
h12 = np.sum(f[:2]) ** 2 + np.sum(f[2:] ** 2)
776+
h12 = np.sum(f[:2]) ** 2 + np.sum(f[2:] ** 2) # type: ignore[index]
777777

778778
# compute H123
779-
h123 = np.sum(f[:3]) ** 2 + np.sum(f[3:] ** 2)
779+
h123 = np.sum(f[:3]) ** 2 + np.sum(f[3:] ** 2) # type: ignore[index]
780780

781781
# compute H2/H1
782-
h2 = h1 - f[0] ** 2
782+
h2 = h1 - f[0] ** 2 # type: ignore[index]
783783
h2_h1 = h2 / h1
784784

785785
return np.array([h1, h12, h123, h2_h1])

sgkit/stats/regenie.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def ridge_regression(
151151
# https://github.com/projectglow/glow/issues/266
152152
diag[:n_zero_reg] = 1
153153
diags.append(np.diag(diag)) # type: ignore[no-untyped-call]
154-
diags = np.stack(diags)
154+
diags = np.stack(diags) # type: ignore[assignment]
155155
B = np.linalg.inv(XtX + diags) @ XtY # type: ignore[no-untyped-call]
156156
B = B.astype(dtype or XtX.dtype)
157157
assert_array_shape(B, n_alpha, n_obs, n_outcome)
@@ -363,8 +363,8 @@ def _stage_2(
363363
alphas = get_alphas(n_variant_block * n_alpha_1)
364364
n_alpha_2 = alphas.size
365365

366-
YR = []
367-
BR = []
366+
YR_list = []
367+
BR_list = []
368368
for i in range(n_outcome):
369369
# Slice and reshape to new 2D covariate matrix;
370370
# The order of raveling in trailing dimensions is important
@@ -382,11 +382,11 @@ def _stage_2(
382382
BB, YPB = _ridge_regression_cv(XPB, YB, alphas, n_zero_reg=n_covar)[-2:]
383383
assert_array_shape(BB, n_alpha_2, n_sample_block * n_indvar, 1)
384384
assert_array_shape(YPB, n_alpha_2, n_sample, 1)
385-
BR.append(BB)
386-
YR.append(YPB)
385+
BR_list.append(BB)
386+
YR_list.append(YPB)
387387

388388
# Concatenate predictions along outcome dimension
389-
YR = da.concatenate(YR, axis=2)
389+
YR = da.concatenate(YR_list, axis=2)
390390
assert_block_shape(YR, 1, n_sample_block, n_outcome)
391391
assert_chunk_shape(YR, n_alpha_2, sample_chunks[0], 1)
392392
assert_array_shape(YR, n_alpha_2, n_sample, n_outcome)
@@ -399,7 +399,7 @@ def _stage_2(
399399
assert YR.shape[1:] == Y.T.shape
400400

401401
# Concatenate betas along outcome dimension
402-
BR = da.concatenate(BR, axis=2)
402+
BR = da.concatenate(BR_list, axis=2)
403403
assert_block_shape(BR, 1, n_sample_block, n_outcome)
404404
assert_chunk_shape(BR, n_alpha_2, n_indvar, 1)
405405
assert_array_shape(BR, n_alpha_2, n_sample_block * n_indvar, n_outcome)

sgkit/tests/test_association.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ def ds() -> Dataset:
146146
def _sm_statistics(
147147
ds: Dataset, i: int, add_intercept: bool
148148
) -> RegressionResultsWrapper:
149-
X = []
149+
X_list = []
150150
# Make sure first independent variable is variant
151-
X.append(ds["dosage"].values[i])
151+
X_list.append(ds["dosage"].values[i])
152152
for v in [c for c in list(ds.keys()) if c.startswith("covar_")]:
153-
X.append(ds[v].values)
153+
X_list.append(ds[v].values)
154154
if add_intercept:
155-
X.append(np.ones(ds.dims["samples"]))
156-
X = np.stack(X).T
155+
X_list.append(np.ones(ds.dims["samples"]))
156+
X = np.stack(X_list).T
157157
y = ds[f"trait_{i}"].values
158158

159159
return sm.OLS(y, X, hasconst=True).fit()

sgkit/tests/test_distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def create_distance_matrix(
8080
chunks,
8181
device,
8282
metric,
83-
marks=pytest.mark.gpu if device == "gpu" else "",
83+
marks=pytest.mark.gpu if device == "gpu" else "", # type: ignore[arg-type]
8484
)
8585
for shape in [(30, 30), (15, 30), (30, 15)]
8686
for chunks in [(10, 10), (5, 10), (10, 5)]

validation/gwas/method/regenie/glow_wgr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore
12
import os
23
import sys
34

0 commit comments

Comments
 (0)