Skip to content

Commit 358a338

Browse files
deprecate 3.8, add 3.9 (#90)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9bdb171 commit 358a338

15 files changed

Lines changed: 107 additions & 114 deletions

‎.mypy.ini‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.8
2+
python_version = 3.9
33
plugins = numpy.typing.mypy_plugin
44

55
ignore_errors = False

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ repos:
7474
rev: v3.3.1
7575
hooks:
7676
- id: pyupgrade
77-
args: [--py3-plus, --py38-plus, --keep-runtime-typing]
77+
args: [--py3-plus, --py39-plus, --keep-runtime-typing]
7878
- repo: https://github.com/pre-commit/pygrep-hooks
7979
rev: v1.9.0
8080
hooks:

‎.readthedocs.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build:
66
python: "3.10"
77
sphinx:
88
configuration: docs/conf.py
9-
fail_on_warning: true
9+
fail_on_warning: false
1010
python:
1111
install:
1212
- method: pip

‎docs/api.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ The elements (building-blocks) that consitute `SpatialData`.
3535

3636
#### Polygons
3737

38+
```{eval-rst}
39+
.. autosummary::
40+
:toctree: generated
41+
42+
PolygonsModel
43+
```
44+
3845
#### Shapes
3946

4047
```{eval-rst}

‎docs/conf.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
"_build",
103103
"Thumbs.db",
104104
"**.ipynb_checkpoints",
105-
"generated/spatialdata.PolygonsModel.rst",
106105
]
107106
# Ignore warnings.
108107
nitpicky = False # TODO: solve upstream.

‎pyproject.toml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[build-system]
2-
build-backend = "flit_core.buildapi"
3-
requires = [
4-
"flit_core >=3.4,<4",
5-
"importlib_metadata>=0.7; python_version < '3.8'",
6-
]
2+
build-backend = "hatchling.build"
3+
requires = ["hatchling"]
74

85

96
[project]
@@ -19,7 +16,7 @@ urls.Documentation = "https://spatialdata.readthedocs.io/"
1916
urls.Source = "https://github.com/scverse/spatialdata.git"
2017
urls.Home-page = "https://github.com/scverse/spatialdata.git"
2118
version = "0.0.1.dev0"
22-
requires-python = ">=3.8"
19+
requires-python = ">=3.9"
2320
license = {file = "LICENSE"}
2421
readme = "README.md"
2522
dependencies = [
@@ -86,7 +83,7 @@ skip_glob = ["docs/*"]
8683

8784
[tool.black]
8885
line-length = 120
89-
target-version = ['py38']
86+
target-version = ['py39']
9087
include = '\.pyi?$'
9188
exclude = '''
9289
(
@@ -110,3 +107,6 @@ formats = "ipynb,md"
110107

111108
[tool.doc8]
112109
ignore-path = "/docs/_templates/autosummary/*.rst"
110+
111+
[tool.hatch.metadata]
112+
allow-direct-references = true

‎spatialdata/_constants/_enum.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC, ABCMeta
22
from enum import Enum, EnumMeta
33
from functools import wraps
4-
from typing import Any, Callable, Dict, Tuple, Type
4+
from typing import Any, Callable
55

66

77
class PrettyEnum(Enum):
@@ -19,7 +19,7 @@ def __str__(self) -> str:
1919
return f"{self.value!s}"
2020

2121

22-
def _pretty_raise_enum(cls: Type["ErrorFormatterABC"], func: Callable[..., Any]) -> Callable[..., Any]:
22+
def _pretty_raise_enum(cls: type["ErrorFormatterABC"], func: Callable[..., Any]) -> Callable[..., Any]:
2323
@wraps(func)
2424
def wrapper(*args: Any, **kwargs: Any) -> "ErrorFormatterABC":
2525
try:
@@ -44,7 +44,7 @@ def __call__(cls, *args: Any, **kwargs: Any) -> Any:
4444
raise TypeError(f"Can't instantiate class `{cls.__name__}` " f"without `__error_format__` class attribute.")
4545
return super().__call__(*args, **kwargs)
4646

47-
def __new__(cls, clsname: str, superclasses: Tuple[type], attributedict: Dict[str, Any]) -> "ABCEnumMeta":
47+
def __new__(cls, clsname: str, superclasses: tuple[type], attributedict: dict[str, Any]) -> "ABCEnumMeta":
4848
res = super().__new__(cls, clsname, superclasses, attributedict) # type: ignore[arg-type]
4949
res.__new__ = _pretty_raise_enum(res, res.__new__) # type: ignore[assignment,arg-type]
5050
return res

‎spatialdata/_core/_spatialdata.py‎

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

33
import hashlib
4+
from collections.abc import Generator, Mapping
45
from types import MappingProxyType
5-
from typing import Dict, Generator, List, Mapping, Optional, Union
6+
from typing import Optional, Union
67

78
import pyarrow as pa
89
import zarr
@@ -110,7 +111,7 @@ def __init__(
110111
) -> None:
111112

112113
if images is not None:
113-
self._images: Dict[str, Union[SpatialImage, MultiscaleSpatialImage]] = {}
114+
self._images: dict[str, Union[SpatialImage, MultiscaleSpatialImage]] = {}
114115
for k, v in images.items():
115116
ndim = len(get_dims(v))
116117
if ndim == 3:
@@ -123,7 +124,7 @@ def __init__(
123124
raise ValueError("Only czyx and cyx images supported")
124125

125126
if labels is not None:
126-
self._labels: Dict[str, Union[SpatialImage, MultiscaleSpatialImage]] = {}
127+
self._labels: dict[str, Union[SpatialImage, MultiscaleSpatialImage]] = {}
127128
for k, v in labels.items():
128129
ndim = len(get_dims(v))
129130
if ndim == 2:
@@ -136,19 +137,19 @@ def __init__(
136137
raise ValueError(f"Invalid label dimensions: {ndim}")
137138

138139
if polygons is not None:
139-
self._polygons: Dict[str, GeoDataFrame] = {}
140+
self._polygons: dict[str, GeoDataFrame] = {}
140141
for k, v in polygons.items():
141142
Polygon_s.validate(v)
142143
self._polygons[k] = v
143144

144145
if shapes is not None:
145-
self._shapes: Dict[str, AnnData] = {}
146+
self._shapes: dict[str, AnnData] = {}
146147
for k, v in shapes.items():
147148
Shape_s.validate(v)
148149
self._shapes[k] = v
149150

150151
if points is not None:
151-
self._points: Dict[str, pa.Table] = {}
152+
self._points: dict[str, pa.Table] = {}
152153
for k, v in points.items():
153154
Point_s.validate(v)
154155
self._points[k] = v
@@ -160,7 +161,7 @@ def __init__(
160161
def write(
161162
self,
162163
file_path: str,
163-
storage_options: Optional[Union[JSONDict, List[JSONDict]]] = None,
164+
storage_options: Optional[Union[JSONDict, list[JSONDict]]] = None,
164165
) -> None:
165166
"""Write to Zarr file."""
166167

@@ -249,7 +250,7 @@ def shapes(self) -> Mapping[str, AnnData]:
249250
"""Return shapes as a mapping of name to shape data."""
250251
return self._shapes
251252

252-
def _non_empty_elements(self) -> List[str]:
253+
def _non_empty_elements(self) -> list[str]:
253254
"""Get the names of the elements that are not empty.
254255
255256
Returns

‎spatialdata/_core/coordinate_system.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import json
2-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
2+
from typing import TYPE_CHECKING, Any, Optional, Union
33

44
__all__ = ["CoordinateSystem", "Axis"]
55

6-
Axis_t = Dict[str, str]
7-
CoordSystem_t = Dict[str, Union[str, List[Dict[str, str]]]]
6+
Axis_t = dict[str, str]
7+
CoordSystem_t = dict[str, Union[str, list[dict[str, str]]]]
88
AXIS_ORDER = ["t", "c", "z", "y", "x"]
99

1010

@@ -30,7 +30,7 @@ def to_dict(self) -> Axis_t:
3030

3131

3232
class CoordinateSystem:
33-
def __init__(self, name: Optional[str] = None, axes: Optional[List[Axis]] = None):
33+
def __init__(self, name: Optional[str] = None, axes: Optional[list[Axis]] = None):
3434
self._name = name
3535
self._axes = axes if axes is not None else []
3636

@@ -67,7 +67,7 @@ def from_dict(coord_sys: CoordSystem_t) -> "CoordinateSystem":
6767
return CoordinateSystem(name=name, axes=axes)
6868

6969
def to_dict(self) -> CoordSystem_t:
70-
out: Dict[str, Any] = {"name": self.name, "axes": [axis.to_dict() for axis in self._axes]}
70+
out: dict[str, Any] = {"name": self.name, "axes": [axis.to_dict() for axis in self._axes]}
7171
# if TYPE_CHECKING:
7272
# assert isinstance(out["axes"], list)
7373
return out
@@ -94,11 +94,11 @@ def name(self) -> Optional[str]:
9494
return self._name
9595

9696
@property
97-
def axes_names(self) -> Tuple[str, ...]:
97+
def axes_names(self) -> tuple[str, ...]:
9898
return tuple([ax.name for ax in self._axes])
9999

100100
@property
101-
def axes_types(self) -> Tuple[str, ...]:
101+
def axes_types(self) -> tuple[str, ...]:
102102
return tuple([ax.type for ax in self._axes])
103103

104104
def __hash__(self) -> int:

‎spatialdata/_core/core_utils.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import copy
22
import json
33
from functools import singledispatch
4-
from typing import Optional, Tuple, Union
4+
from typing import Optional, Union
55

66
import pyarrow as pa
77
from anndata import AnnData
@@ -160,7 +160,7 @@ def _(e: pa.Table, t: BaseTransformation) -> pa.Table:
160160

161161

162162
@singledispatch
163-
def get_dims(e: SpatialElement) -> Tuple[str, ...]:
163+
def get_dims(e: SpatialElement) -> tuple[str, ...]:
164164
"""
165165
Get the dimensions of a spatial element
166166
@@ -178,33 +178,33 @@ def get_dims(e: SpatialElement) -> Tuple[str, ...]:
178178

179179

180180
@get_dims.register(SpatialImage)
181-
def _(e: SpatialImage) -> Tuple[str, ...]:
181+
def _(e: SpatialImage) -> tuple[str, ...]:
182182
dims = e.dims
183183
return dims # type: ignore
184184

185185

186186
@get_dims.register(MultiscaleSpatialImage)
187-
def _(e: MultiscaleSpatialImage) -> Tuple[str, ...]:
187+
def _(e: MultiscaleSpatialImage) -> tuple[str, ...]:
188188
variables = list(e[list(e.keys())[0]].variables)
189189
return e[list(e.keys())[0]][variables[0]].dims # type: ignore
190190

191191

192192
@get_dims.register(GeoDataFrame)
193-
def _(e: GeoDataFrame) -> Tuple[str, ...]:
193+
def _(e: GeoDataFrame) -> tuple[str, ...]:
194194
dims = (X, Y, Z)
195195
n = e.geometry.iloc[0]._ndim
196196
return dims[:n]
197197

198198

199199
@get_dims.register(AnnData)
200-
def _(e: AnnData) -> Tuple[str, ...]:
200+
def _(e: AnnData) -> tuple[str, ...]:
201201
dims = (X, Y, Z)
202202
n = e.obsm["spatial"].shape[1]
203203
return dims[:n]
204204

205205

206206
@get_dims.register(pa.Table)
207-
def _(e: pa.Table) -> Tuple[str, ...]:
207+
def _(e: pa.Table) -> tuple[str, ...]:
208208
valid_dims = (X, Y, Z)
209209
dims = [c for c in valid_dims if c in e.column_names]
210210
return tuple(dims)

0 commit comments

Comments
 (0)