Skip to content

Commit c6f4f1c

Browse files
fix: remove unused parameters in co_occurence (#1121)
* remove the params * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * recommit * update nb --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ff5f98f commit c6f4f1c

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

src/squidpy/_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,37 @@ def verbosity(level: int) -> Generator[None, None, None]:
278278
sc.settings.verbosity = verbosity
279279

280280

281+
def deprecated_params(
282+
params: dict[str, str],
283+
) -> Callable[..., Any]:
284+
"""Decorator that warns when deprecated keyword arguments are passed.
285+
286+
Parameters
287+
----------
288+
params
289+
Mapping of deprecated parameter names to the version in which
290+
they will be removed, e.g. ``{"n_jobs": "1.10.0"}``.
291+
"""
292+
293+
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
294+
@functools.wraps(func)
295+
def wrapper(*args: Any, **kwargs: Any) -> Any:
296+
for k in list(kwargs):
297+
if k in params:
298+
warnings.warn(
299+
f"Parameter `{k}` of `{func.__name__}()` is deprecated "
300+
f"and has no effect. It will be removed in squidpy v{params[k]}.",
301+
FutureWarning,
302+
stacklevel=2,
303+
)
304+
kwargs.pop(k)
305+
return func(*args, **kwargs)
306+
307+
return wrapper
308+
309+
return decorator
310+
311+
281312
string_types = (bytes, str)
282313

283314

src/squidpy/gr/_ppatterns.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from squidpy._constants._constants import SpatialAutocorr
2424
from squidpy._constants._pkg_constants import Key
2525
from squidpy._docs import d, inject_docs
26-
from squidpy._utils import NDArrayA, Signal, SigQueue, _get_n_cores, parallelize
26+
from squidpy._utils import NDArrayA, Signal, SigQueue, _get_n_cores, deprecated_params, parallelize
2727
from squidpy.gr._utils import (
2828
_assert_categorical_obs,
2929
_assert_connectivity_key,
@@ -342,16 +342,13 @@ def _co_occurrence_helper(v_x: NDArrayA, v_y: NDArrayA, v_radium: NDArrayA, labs
342342

343343

344344
@d.dedent
345+
@deprecated_params({"n_splits": "1.10.0", "n_jobs": "1.10.0", "backend": "1.10.0", "show_progress_bar": "1.10.0"})
345346
def co_occurrence(
346347
adata: AnnData | SpatialData,
347348
cluster_key: str,
348349
spatial_key: str = Key.obsm.spatial,
349350
interval: int | NDArrayA = 50,
350351
copy: bool = False,
351-
n_splits: int | None = None,
352-
n_jobs: int | None = None,
353-
backend: str = "loky",
354-
show_progress_bar: bool = True,
355352
) -> tuple[NDArrayA, NDArrayA] | None:
356353
"""
357354
Compute co-occurrence probability of clusters.
@@ -365,10 +362,6 @@ def co_occurrence(
365362
Distances interval at which co-occurrence is computed. If :class:`int`, uniformly spaced interval
366363
of the given size will be used.
367364
%(copy)s
368-
n_splits
369-
Number of splits in which to divide the spatial coordinates in
370-
:attr:`anndata.AnnData.obsm` ``['{spatial_key}']``.
371-
%(parallelize)s
372365
373366
Returns
374367
-------
@@ -406,9 +399,7 @@ def co_occurrence(
406399

407400
# Compute co-occurrence probabilities using the fast numba routine.
408401
out = _co_occurrence_helper(spatial_x, spatial_y, interval, labs)
409-
start = logg.info(
410-
f"Calculating co-occurrence probabilities for `{len(interval)}` intervals using `{n_jobs}` core(s) and `{n_splits}` splits"
411-
)
402+
start = logg.info(f"Calculating co-occurrence probabilities for `{len(interval)}` intervals")
412403

413404
if copy:
414405
logg.info("Finish", time=start)

tests/graph/test_ppatterns.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,10 @@ def test_co_occurrence(adata: AnnData):
137137
assert arr.shape[1] == arr.shape[0] == adata.obs["leiden"].unique().shape[0]
138138

139139

140-
# @pytest.mark.parametrize(("ys", "xs"), [(10, 10), (None, None), (10, 20)])
141-
@pytest.mark.parametrize(("n_jobs", "n_splits"), [(1, 2), (2, 2)])
142-
def test_co_occurrence_reproducibility(adata: AnnData, n_jobs: int, n_splits: int):
140+
def test_co_occurrence_reproducibility(adata: AnnData):
143141
"""Check co_occurrence reproducibility results."""
144-
arr_1, interval_1 = co_occurrence(adata, cluster_key="leiden", copy=True, n_jobs=n_jobs, n_splits=n_splits)
145-
arr_2, interval_2 = co_occurrence(adata, cluster_key="leiden", copy=True, n_jobs=n_jobs, n_splits=n_splits)
142+
arr_1, interval_1 = co_occurrence(adata, cluster_key="leiden", copy=True)
143+
arr_2, interval_2 = co_occurrence(adata, cluster_key="leiden", copy=True)
146144

147145
np.testing.assert_array_equal(sorted(interval_1), sorted(interval_2))
148146
np.testing.assert_allclose(arr_1, arr_2)

0 commit comments

Comments
 (0)