Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9ea9c3

Browse files
committedMar 25, 2025
fix
Signed-off-by: Lukas Heumos <lukas.heumos@posteo.net>
1 parent daafe12 commit c9ea9c3

30 files changed

+166
-147
lines changed
 

‎.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
rev: v0.11.2
1515
hooks:
1616
- id: ruff
17-
args: [--fix, --exit-non-zero-on-fix]
17+
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
1818
- id: ruff-format
1919
- repo: https://github.com/pre-commit/mirrors-mypy
2020
rev: v1.15.0

‎docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datetime import datetime
1010
from importlib.metadata import metadata
1111
from pathlib import Path
12+
1213
import spatialdata_io.experimental
1314

1415
_ = spatialdata_io.experimental

‎pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ lint.select = [
103103
"RUF100", # Report unused noqa directives
104104
"TCH", # Typing imports
105105
"NPY", # Numpy specific rules
106-
"PTH", # Use pathlib
107-
"S" # Security
106+
# "PTH", # Use pathlib
107+
# "S" # Security
108108
]
109109
lint.ignore = [
110110
# Do not catch blind exception: `Exception`

‎src/spatialdata_io/__main__.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
@click.group()
3131
def cli() -> None:
32-
"""
33-
Convert standard technology data formats to SpatialData object.
32+
"""Convert standard technology data formats to SpatialData object.
3433
3534
Usage:
3635
@@ -66,7 +65,7 @@ def _input_output_click_options(func: Callable[..., None]) -> Callable[..., None
6665
help="Whether the .fcs file is provided if False a .csv file is expected. [default: True]",
6766
)
6867
def codex_wrapper(input: str, output: str, fcs: bool = True) -> None:
69-
"""Codex conversion to SpatialData"""
68+
"""Codex conversion to SpatialData."""
7069
sdata = codex(input, fcs=fcs) # type: ignore[name-defined] # noqa: F821
7170
sdata.write(output)
7271

@@ -76,15 +75,15 @@ def codex_wrapper(input: str, output: str, fcs: bool = True) -> None:
7675
@click.option("--dataset-id", type=str, default=None, help="Name of the dataset [default: None]")
7776
@click.option("--transcripts", type=bool, default=True, help="Whether to load transcript information. [default: True]")
7877
def cosmx_wrapper(input: str, output: str, dataset_id: str | None = None, transcripts: bool = True) -> None:
79-
"""Cosmic conversion to SpatialData"""
78+
"""Cosmic conversion to SpatialData."""
8079
sdata = cosmx(input, dataset_id=dataset_id, transcripts=transcripts) # type: ignore[name-defined] # noqa: F821
8180
sdata.write(output)
8281

8382

8483
@cli.command(name="curio")
8584
@_input_output_click_options
8685
def curio_wrapper(input: str, output: str) -> None:
87-
"""Curio conversion to SpatialData"""
86+
"""Curio conversion to SpatialData."""
8887
sdata = curio(input) # type: ignore[name-defined] # noqa: F821
8988
sdata.write(output)
9089

@@ -117,7 +116,7 @@ def dbit_wrapper(
117116
border: bool = True,
118117
border_scale: float = 1,
119118
) -> None:
120-
"""Conversion of DBit-seq to SpatialData"""
119+
"""Conversion of DBit-seq to SpatialData."""
121120
sdata = dbit( # type: ignore[name-defined] # noqa: F821
122121
input,
123122
anndata_path=anndata_path,
@@ -174,7 +173,7 @@ def iss_wrapper(
174173
multiscale_image: bool = True,
175174
multiscale_labels: bool = True,
176175
) -> None:
177-
"""ISS conversion to SpatialData"""
176+
"""ISS conversion to SpatialData."""
178177
sdata = iss( # type: ignore[name-defined] # noqa: F821
179178
input,
180179
raw_relative_path,
@@ -194,7 +193,7 @@ def iss_wrapper(
194193
)
195194
@click.option("--output", "-o", type=click.Path(), help="Path to the output.zarr file.", required=True)
196195
def mcmicro_wrapper(input: str, output: str) -> None:
197-
"""Conversion of MCMicro to SpatialData"""
196+
"""Conversion of MCMicro to SpatialData."""
198197
sdata = mcmicro(input) # type: ignore[name-defined] # noqa: F821
199198
sdata.write(output)
200199

@@ -233,7 +232,7 @@ def merscope_wrapper(
233232
cells_table: bool = True,
234233
mosaic_images: bool = True,
235234
) -> None:
236-
"""Merscope conversion to SpatialData"""
235+
"""Merscope conversion to SpatialData."""
237236
sdata = merscope( # type: ignore[name-defined] # noqa: F821
238237
input,
239238
vpt_outputs=vpt_outputs,
@@ -273,7 +272,7 @@ def seqfish_wrapper(
273272
cells_as_circles: bool = False,
274273
rois: list[int] | None = None,
275274
) -> None:
276-
"""Seqfish conversion to SpatialData"""
275+
"""Seqfish conversion to SpatialData."""
277276
rois = list(rois) if rois else None
278277
sdata = seqfish( # type: ignore[name-defined] # noqa: F821
279278
input,
@@ -296,7 +295,7 @@ def seqfish_wrapper(
296295
help="What kind of labels to use. [default: 'deepcell']",
297296
)
298297
def steinbock_wrapper(input: str, output: str, labels_kind: Literal["deepcell", "ilastik"] = "deepcell") -> None:
299-
"""Steinbock conversion to SpatialData"""
298+
"""Steinbock conversion to SpatialData."""
300299
sdata = steinbock(input, labels_kind=labels_kind) # type: ignore[name-defined] # noqa: F821
301300
sdata.write(output)
302301

@@ -320,7 +319,7 @@ def stereoseq_wrapper(
320319
read_square_bin: bool = True,
321320
optional_tif: bool = False,
322321
) -> None:
323-
"""Stereoseq conversion to SpatialData"""
322+
"""Stereoseq conversion to SpatialData."""
324323
sdata = stereoseq(input, dataset_id=dataset_id, read_square_bin=read_square_bin, optional_tif=optional_tif) # type: ignore[name-defined] # noqa: F821
325324
sdata.write(output)
326325

@@ -361,7 +360,7 @@ def visium_wrapper(
361360
tissue_positions_file: str | Path | None = None,
362361
scalefactors_file: str | Path | None = None,
363362
) -> None:
364-
"""Visium conversion to SpatialData"""
363+
"""Visium conversion to SpatialData."""
365364
sdata = visium( # type: ignore[name-defined] # noqa: F821
366365
input,
367366
dataset_id=dataset_id,
@@ -424,7 +423,7 @@ def visium_hd_wrapper(
424423
load_all_images: bool = False,
425424
annotate_table_by_labels: bool = False,
426425
) -> None:
427-
"""Visium HD conversion to SpatialData"""
426+
"""Visium HD conversion to SpatialData."""
428427
sdata = visium_hd( # type: ignore[name-defined] # noqa: F821
429428
path=input,
430429
dataset_id=dataset_id,
@@ -483,7 +482,7 @@ def xenium_wrapper(
483482
cells_table: bool = True,
484483
n_jobs: int = 1,
485484
) -> None:
486-
"""Xenium conversion to SpatialData"""
485+
"""Xenium conversion to SpatialData."""
487486
sdata = xenium( # type: ignore[name-defined] # noqa: F821
488487
input,
489488
cells_boundaries=cells_boundaries,
@@ -637,7 +636,7 @@ def read_generic_wrapper(
637636
data_axes: str | None = None,
638637
coordinate_system: str | None = None,
639638
) -> None:
640-
"""Read generic data to SpatialData"""
639+
"""Read generic data to SpatialData."""
641640
generic_to_zarr(input=input, output=output, name=name, data_axes=data_axes, coordinate_system=coordinate_system)
642641

643642

‎src/spatialdata_io/_constants/_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class McmicroKeys(ModeEnum):
301301

302302
@unique
303303
class MerscopeKeys(ModeEnum):
304-
"""Keys for *MERSCOPE* data (Vizgen plateform)"""
304+
"""Keys for *MERSCOPE* data (Vizgen plateform)."""
305305

306306
# files and directories
307307
IMAGES_DIR = "images"

‎src/spatialdata_io/_constants/_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __new__(cls, clsname: str, superclasses: tuple[type], attributedict: dict[st
5151
return res
5252

5353

54-
class ErrorFormatterABC(ABC):
54+
class ErrorFormatterABC(ABC): # noqa
5555
"""Mixin class that formats invalid value when constructing an enum."""
5656

5757
__error_format__ = "Invalid option `{0}` for `{1}`. Valid options are: `{2}`."

‎src/spatialdata_io/_docs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable
43
from textwrap import dedent
5-
from typing import Any
4+
from typing import TYPE_CHECKING, Any
65

6+
if TYPE_CHECKING:
7+
from collections.abc import Callable
78

8-
def inject_docs(**kwargs: Any) -> Callable[..., Any]: # noqa: D103
9+
10+
def inject_docs(**kwargs: Any) -> Callable[..., Any]:
911
# taken from scanpy
1012
def decorator(obj: Any) -> Any:
1113
obj.__doc__ = dedent(obj.__doc__).format(**kwargs)

‎src/spatialdata_io/_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
import functools
44
import warnings
5-
from collections.abc import Callable
6-
from typing import Any, TypeVar
5+
from typing import TYPE_CHECKING, Any, TypeVar
6+
7+
if TYPE_CHECKING:
8+
from collections.abc import Callable
79

810
RT = TypeVar("RT")
911

1012

1113
# these two functions should be removed and imported from spatialdata._utils once the multi_table branch, which
1214
# introduces them, is merged
1315
def deprecation_alias(**aliases: str) -> Callable[[Callable[..., RT]], Callable[..., RT]]:
14-
"""
15-
Decorate a function to warn user of use of arguments set for deprecation.
16+
"""Decorate a function to warn user of use of arguments set for deprecation.
1617
1718
Parameters
1819
----------

‎src/spatialdata_io/converters/generic_to_zarr.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def generic_to_zarr(
2121
data_axes: str | None = None,
2222
coordinate_system: str | None = None,
2323
) -> None:
24-
"""
25-
Read generic data from an input file and save it as a SpatialData zarr store.
24+
"""Read generic data from an input file and save it as a SpatialData zarr store.
2625
2726
Parameters
2827
----------

‎src/spatialdata_io/converters/legacy_anndata.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

33
import warnings
4+
from typing import TYPE_CHECKING
45

56
import numpy as np
6-
from anndata import AnnData
77
from spatialdata import (
88
SpatialData,
99
get_centroids,
@@ -15,15 +15,17 @@
1515
from spatialdata.models import Image2DModel, ShapesModel, TableModel, get_table_keys
1616
from spatialdata.transformations import Identity, Scale
1717

18+
if TYPE_CHECKING:
19+
from anndata import AnnData
20+
1821

1922
def to_legacy_anndata(
2023
sdata: SpatialData,
2124
coordinate_system: str | None = None,
2225
table_name: str | None = None,
2326
include_images: bool = False,
2427
) -> AnnData:
25-
"""
26-
Convert a SpatialData object to a (legacy) spatial AnnData object.
28+
"""Convert a SpatialData object to a (legacy) spatial AnnData object.
2729
2830
This is useful for using packages expecting spatial information in AnnData, for example Scanpy and older versions
2931
of Squidpy. Using this format for any new package is not recommended.
@@ -219,8 +221,7 @@ def to_legacy_anndata(
219221

220222

221223
def from_legacy_anndata(adata: AnnData) -> SpatialData:
222-
"""
223-
Convert (legacy) spatial AnnData object to SpatialData object.
224+
"""Convert (legacy) spatial AnnData object to SpatialData object.
224225
225226
This is useful for parsing a (legacy) spatial AnnData object, for example the ones produced by Scanpy and older
226227
version of Squidpy.

‎src/spatialdata_io/readers/_utils/_read_10x_h5.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def _read_10x_h5(
4444
genome: str | None = None,
4545
gex_only: bool = True,
4646
) -> AnnData:
47-
"""
48-
Read 10x-Genomics-formatted hdf5 file.
47+
"""Read 10x-Genomics-formatted hdf5 file.
4948
5049
Parameters
5150
----------
@@ -126,7 +125,7 @@ def _read_v3_10x_h5(filename: str | Path, *, start: Any | None = None) -> AnnDat
126125
)
127126
return adata
128127
except KeyError:
129-
raise Exception("File is missing one or more required datasets.")
128+
raise Exception("File is missing one or more required datasets.") from None
130129

131130

132131
def _collect_datasets(dsets: dict[str, Any], group: h5py.Group) -> None:

‎src/spatialdata_io/readers/_utils/_utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

33
import os
4-
from collections.abc import Mapping
54
from pathlib import Path
6-
from typing import Any, Union
5+
from typing import TYPE_CHECKING, Any, Union
76

8-
from anndata import AnnData
97
from anndata.io import read_text
108
from h5py import File
119
from ome_types import from_tiff
@@ -14,7 +12,12 @@
1412

1513
from spatialdata_io.readers._utils._read_10x_h5 import _read_10x_h5
1614

17-
PathLike = Union[os.PathLike, str] # type:ignore[type-arg]
15+
if TYPE_CHECKING:
16+
from collections.abc import Mapping
17+
18+
from anndata import AnnData
19+
20+
PathLike = os.PathLike | str # type:ignore[type-arg]
1821

1922

2023
def _read_counts(
@@ -54,7 +57,7 @@ def _read_counts(
5457
try:
5558
from scanpy.readwrite import read_10x_mtx
5659
except ImportError:
57-
raise ImportError("Please install scanpy to read 10x mtx files, `pip install scanpy`.")
60+
raise ImportError("Please install scanpy to read 10x mtx files, `pip install scanpy`.") from None
5861
prefix = counts_file.replace("matrix.mtx.gz", "")
5962
adata = read_10x_mtx(path, prefix=prefix, **kwargs)
6063
else:

‎src/spatialdata_io/readers/codex.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import os
44
import re
5-
from collections.abc import Mapping
65
from pathlib import Path
76
from types import MappingProxyType
8-
from typing import Any
7+
from typing import TYPE_CHECKING, Any
98

109
import anndata as ad
1110
import pandas as pd
@@ -18,6 +17,9 @@
1817
from spatialdata_io._constants._constants import CodexKeys
1918
from spatialdata_io._docs import inject_docs
2019

20+
if TYPE_CHECKING:
21+
from collections.abc import Mapping
22+
2123
__all__ = ["codex"]
2224

2325

@@ -27,8 +29,7 @@ def codex(
2729
fcs: bool = True,
2830
imread_kwargs: Mapping[str, Any] = MappingProxyType({}),
2931
) -> SpatialData:
30-
"""
31-
Read *CODEX* formatted dataset.
32+
"""Read *CODEX* formatted dataset.
3233
3334
This function reads the following files:
3435

0 commit comments

Comments
 (0)