Skip to content

Commit 02fb792

Browse files
committed
fix precommit hooks
1 parent 23cf1a2 commit 02fb792

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/squidpy/gr/_nhood.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,32 @@ def _create_function(n_cls: int, parallel: bool = False) -> Callable[[NDArrayA,
118118
return globals()[fn_key] # type: ignore[no-any-return]
119119

120120

121-
def filter_clusters_by_min_cell_count(adata, int_clust, connectivity_key, min_cell_count):
121+
def filter_clusters_by_min_cell_count(
122+
adata: AnnData,
123+
int_clust: NDArrayA,
124+
connectivity_key: str,
125+
min_cell_count: int,
126+
) -> tuple[NDArrayA, NDArrayA]:
127+
"""
128+
Filter clusters by minimum cell count.
129+
130+
Parameters
131+
----------
132+
%(adata)s
133+
int_clust
134+
Array of cluster labels per cell
135+
connectivity_key
136+
Key in adata.obsp with adjacency matrix
137+
min_cell_count
138+
Minimum number of cells required to keep a cluster
139+
140+
Returns
141+
-------
142+
int_clust_filtered
143+
Filtered cluster labels
144+
adj
145+
Adjacency matrix corresponding to filtered cells
146+
"""
122147
clust_sizes = pd.Series(int_clust).value_counts()
123148
valid_clusters = clust_sizes[clust_sizes >= min_cell_count].index.to_numpy()
124149

@@ -147,7 +172,7 @@ def nhood_enrichment(
147172
min_cell_count: int = 10,
148173
handle_nan: str = "keep",
149174
show_progress_bar: bool = True,
150-
) -> tuple[NDArrayA, NDArrayA] | None:
175+
) -> tuple[NDArrayA, NDArrayA] | tuple[NDArrayA, NDArrayA, NDArrayA] | None:
151176
"""
152177
Compute neighborhood enrichment by permutation test.
153178
@@ -211,7 +236,7 @@ def nhood_enrichment(
211236

212237
_test = _create_function(n_cls, parallel=numba_parallel)
213238
count = _test(indices, indptr, int_clust)
214-
conditional_ratio = None
239+
conditional_ratio = np.full((n_cls, n_cls), np.nan, dtype=np.float64)
215240

216241
if normalization == "total":
217242
row_sums = count.sum(axis=1, keepdims=True)
@@ -568,7 +593,6 @@ def _nhood_enrichment_helper(
568593
has_b_neighbor = per_cell_neighbor_matrix[a_cells, b]
569594
cond_counts[a, b] = has_b_neighbor.sum()
570595

571-
low_count_mask = cond_counts < min_cond_count
572596
cond_counts[cond_counts == 0] = 1.0
573597
count_perms = count_perms / cond_counts
574598

src/squidpy/im/_io.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from collections.abc import Mapping
44
from pathlib import Path
5+
from typing import Any
56

67
import dask.array as da
78
import numpy as np
@@ -25,7 +26,7 @@ def _assert_dims_present(dims: tuple[str, ...], include_z: bool = True) -> None:
2526

2627
# modification of `skimage`'s `pil_to_ndarray`:
2728
# https://github.com/scikit-image/scikit-image/blob/main/skimage/io/_plugins/pil_plugin.py#L55
28-
def _infer_shape_dtype(fname: str) -> tuple[tuple[int, ...], np.dtype]:
29+
def _infer_shape_dtype(fname: str) -> tuple[tuple[int, ...], np.dtype[Any]]:
2930
def _palette_is_grayscale(pil_image: Image.Image) -> bool:
3031
# get palette as an array with R, G, B columns
3132
palette = np.asarray(pil_image.getpalette()).reshape((256, 3))
@@ -81,7 +82,7 @@ def _palette_is_grayscale(pil_image: Image.Image) -> bool:
8182
raise ValueError(f"Unable to infer image dtype for image mode `{image.mode}`.")
8283

8384

84-
def _get_image_shape_dtype(fname: str) -> tuple[tuple[int, ...], np.dtype]:
85+
def _get_image_shape_dtype(fname: str) -> tuple[tuple[int, ...], np.dtype[Any]]:
8586
try:
8687
return _infer_shape_dtype(fname)
8788
except Image.UnidentifiedImageError as e:
@@ -101,7 +102,7 @@ def _get_image_shape_dtype(fname: str) -> tuple[tuple[int, ...], np.dtype]:
101102
def _infer_dimensions(
102103
obj: NDArrayA | xr.DataArray | str,
103104
infer_dimensions: InferDimensions | tuple[str, ...] = InferDimensions.DEFAULT,
104-
) -> tuple[tuple[int, ...], tuple[str, ...], np.dtype, tuple[int, ...]]:
105+
) -> tuple[tuple[int, ...], tuple[str, ...], np.dtype[Any], tuple[int, ...]]:
105106
"""
106107
Infer dimension names of an array.
107108

src/squidpy/pl/_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def nhood_enrichment_dotplot(
364364
markersize=np.sqrt(s), # scatter size is area → sqrt for legend
365365
markeredgecolor="black",
366366
)
367-
for v, s in zip(legend_ccr_vals, legend_sizes)
367+
for v, s in zip(legend_ccr_vals, legend_sizes, strict=True)
368368
]
369369

370370
ax.legend(

0 commit comments

Comments
 (0)