Skip to content

Commit 41827f3

Browse files
tomwhitemergify[bot]
authored andcommitted
Fix typing errors when upgrading to NumPy 1.20.0
1 parent c210fae commit 41827f3

File tree

11 files changed

+16
-16
lines changed

11 files changed

+16
-16
lines changed

sgkit/distance/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ def pairwise_distance(
100100
concatenate=True,
101101
)
102102
x_distance = da.triu(x_distance, 1) + da.triu(x_distance).T
103-
return x_distance.compute()
103+
return x_distance.compute() # type: ignore[no-any-return]

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) -> np.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[no-any-return]
149149

150150

151151
def _split_alleles(allele_ids: bytes) -> List[bytes]:
@@ -362,7 +362,7 @@ def encode_variables(
362362
# 16 bits will cause overflow/underflow
363363
# See https://en.wikipedia.org/wiki/Floating-point_arithmetic#Internal_representation
364364
# *bits precision column for single precision floats
365-
if dtype not in [np.uint8, np.uint16]:
365+
if dtype not in [np.uint8, np.uint16]: # type: ignore[comparison-overlap]
366366
raise ValueError(
367367
"Probability integer dtype invalid, must "
368368
f"be uint8 or uint16 not {probability_dtype}"

sgkit/io/plink/plink_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __getitem__(self, idx: Tuple[Any, ...]) -> np.ndarray:
8484
call1 = np.where(arr < 0, -1, np.where(arr == 2, 1, 0))
8585
arr = np.stack([call0, call1], axis=-1)
8686
# Apply final slice to 3D result
87-
return arr[:, :, idx[-1]]
87+
return arr[:, :, idx[-1]] # type: ignore[no-any-return]
8888

8989
def close(self) -> None:
9090
# This is not actually crucial since a Bed instance with no
@@ -265,7 +265,7 @@ def read_plink(
265265
# Otherwise create index for contig names based
266266
# on order of appearance in underlying .bim file
267267
else:
268-
variant_contig, variant_contig_names = encode_array(arr_bim["contig"].compute())
268+
variant_contig, variant_contig_names = encode_array(arr_bim["contig"].compute()) # type: ignore
269269
variant_contig = variant_contig.astype("int16")
270270
variant_contig_names = list(variant_contig_names)
271271

sgkit/io/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def load_chunk(
183183

184184
def _zarr_index(offsets: ArrayLike, pos: int) -> int:
185185
"""Return the index of the zarr file that pos falls in"""
186-
index: int = np.searchsorted(offsets, pos, side="right") - 1
186+
index: int = np.searchsorted(offsets, pos, side="right") - 1 # type: ignore[assignment]
187187
return index
188188

189189

sgkit/io/vcfzarr_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _vcfzarr_to_dataset(
196196
# Compute fixed-length string dtype for array
197197
if kind == "O" or var in ("variant_id", "variant_allele"):
198198
kind = "S"
199-
max_len = max_str_len(arr).values
199+
max_len = max_str_len(arr).values # type: ignore[union-attr]
200200
dt = f"{kind}{max_len}"
201201
ds[var] = arr.astype(dt) # type: ignore[no-untyped-call]
202202

sgkit/stats/hwe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def hardy_weinberg_p_value(obs_hets: int, obs_hom1: int, obs_hom2: int) -> float
4848
het_probs = np.zeros(obs_mac + 1, dtype=np.float64)
4949

5050
if obs_n == 0:
51-
return np.nan # type: ignore[no-any-return]
51+
return np.nan
5252

5353
# Identify distribution midpoint
5454
mid = int(obs_mac * (2 * obs_n - obs_mac) / (2 * obs_n))
@@ -91,7 +91,7 @@ def hardy_weinberg_p_value(obs_hets: int, obs_hom1: int, obs_hom2: int) -> float
9191
curr_hets += 2
9292

9393
if prob_sum <= 0: # pragma: no cover
94-
return np.nan # type: ignore[no-any-return]
94+
return np.nan
9595
het_probs = het_probs / prob_sum
9696
p = het_probs[het_probs <= het_probs[obs_hets]].sum()
9797
p = max(min(1.0, p), 0.0)

sgkit/stats/pca.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def pca_stats(ds: Dataset, est: BaseEstimator, *, merge: bool = True) -> Dataset
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])
133+
] * np.sqrt(new_ds[variables.sample_pca_explained_variance].data)
134134
return conditional_merge_datasets(ds, variables.validate(new_ds), merge)
135135

136136

sgkit/stats/regenie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def regenie_transform(
598598
*,
599599
variant_block_size: Optional[Union[int, Tuple[int, ...]]] = None,
600600
sample_block_size: Optional[Union[int, Tuple[int, ...]]] = None,
601-
alphas: Optional[Sequence[float]] = None,
601+
alphas: Optional[ArrayLike] = None,
602602
add_intercept: bool = True,
603603
orthogonalize: bool = False,
604604
normalize: bool = False,

sgkit/tests/test_pca.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def simulate_cohort_genotypes(
2929
]
3030
)
3131
# Sample allele counts in [0, 1, 2]
32-
return rs.binomial(2, af.T).astype("int8")
32+
return rs.binomial(2, af.T).astype("int8") # type: ignore[no-any-return]
3333

3434

3535
def simulate_dataset(

sgkit/tests/test_preprocessing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_patterson_scaler__missing_data(dtype, use_nan):
8585
ac = np.where(ac < 0, np.nan, ac)
8686
scaler = sgkit.stats.preprocessing.PattersonScaler().fit(ac)
8787
# Read means from columns of array; scale = sqrt(mean/2 * (1 - mean/2))
88-
np.testing.assert_equal(scaler.mean_, np.array([1] * 3 + [np.nan]))
88+
np.testing.assert_equal(scaler.mean_, np.array([1.0] * 3 + [np.nan]))
8989
np.testing.assert_equal(scaler.scale_, np.array([0.5] * 3 + [np.nan]))
9090
np.testing.assert_equal(
9191
scaler.transform(ac),
@@ -121,7 +121,7 @@ def test_filter_partial_calls():
121121

122122
np.testing.assert_array_equal(
123123
mask_filtered,
124-
np.array([[[0, 0], [0, 0], [0, 0]], [[1, 1], [1, 1], [1, 1]]], dtype=np.bool),
124+
np.array([[[0, 0], [0, 0], [0, 0]], [[1, 1], [1, 1], [1, 1]]], dtype=bool),
125125
)
126126

127127

@@ -159,7 +159,7 @@ def test_filter_partial_calls__mixed_ploidy():
159159
[[0, 0, 0, 0], [0, 0, 1, 1], [0, 0, 0, 0]],
160160
[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],
161161
],
162-
dtype=np.bool,
162+
dtype=bool,
163163
),
164164
)
165165

sgkit/window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def has_windows(ds: Dataset) -> bool:
106106

107107

108108
def moving_statistic(
109-
values: ArrayLike,
109+
values: da.Array,
110110
statistic: Callable[..., ArrayLike],
111111
size: int,
112112
step: int,

0 commit comments

Comments
 (0)