diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d38cb35a..c8c0bdc4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,20 +12,20 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.3.0 hooks: - id: black args: [--target-version=py36] - repo: https://github.com/asottile/pyupgrade - rev: v3.2.0 + rev: v3.3.1 hooks: - id: pyupgrade args: - --py36-plus - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace exclude: .bumpversion.cfg @@ -45,7 +45,7 @@ repos: - --autofix - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: [ @@ -64,12 +64,12 @@ repos: ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v1.1.1 hooks: - id: mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v1.1.1 hooks: - id: mypy args: [ @@ -79,7 +79,7 @@ repos: exclude: tests/|setup.py - repo: https://github.com/adrienverge/yamllint.git - rev: v1.28.0 + rev: v1.30.0 hooks: - id: yamllint # args: [--config-data=relaxed] diff --git a/ome_zarr/axes.py b/ome_zarr/axes.py index e761bcbd..1da37266 100644 --- a/ome_zarr/axes.py +++ b/ome_zarr/axes.py @@ -97,7 +97,6 @@ def _get_names(self) -> List[str]: return axes_names def _validate_03(self) -> None: - val_axes = tuple(self._get_names()) if len(val_axes) == 2: if val_axes != ("y", "x"): diff --git a/ome_zarr/cli.py b/ome_zarr/cli.py index 9b778d13..070d98c1 100755 --- a/ome_zarr/cli.py +++ b/ome_zarr/cli.py @@ -73,7 +73,7 @@ def csv_to_labels(args: argparse.Namespace) -> None: csv_to_zarr(args.csv_path, args.csv_id, args.csv_keys, args.zarr_path, args.zarr_id) -def main(args: List[str] = None) -> None: +def main(args: List[str]) -> None: """Run appropriate function with argparse arguments, handling errors.""" parser = argparse.ArgumentParser() parser.add_argument( diff --git a/ome_zarr/csv.py b/ome_zarr/csv.py index 9f52a77e..743ccdbe 100644 --- a/ome_zarr/csv.py +++ b/ome_zarr/csv.py @@ -126,7 +126,6 @@ def dict_to_zarr( labels_paths.append(os.path.join(zarr_path, "labels", "0")) for path_to_labels in labels_paths: - label_group = zarr_open(path_to_labels) attrs = label_group.attrs.asdict() properties = attrs.get("image-label", {}).get("properties") diff --git a/ome_zarr/data.py b/ome_zarr/data.py index 4bcd42fa..56ca140a 100644 --- a/ome_zarr/data.py +++ b/ome_zarr/data.py @@ -1,6 +1,6 @@ """Functions for generating synthetic data.""" from random import randrange -from typing import Callable, List, Tuple, Union +from typing import Callable, List, Optional, Tuple, Union import numpy as np import zarr @@ -103,7 +103,7 @@ def create_zarr( method: Callable[..., Tuple[List, List]] = coins, label_name: str = "coins", fmt: Format = CurrentFormat(), - chunks: Union[Tuple, List] = None, + chunks: Optional[Union[Tuple, List]] = None, ) -> zarr.Group: """Generate a synthetic image pyramid with labels.""" pyramid, labels = method() @@ -170,7 +170,6 @@ def create_zarr( grp.attrs["omero"] = image_data if labels: - labels_grp = grp.create_group("labels") labels_grp.attrs["labels"] = [label_name] diff --git a/ome_zarr/format.py b/ome_zarr/format.py index 98c08d03..6b57b4ff 100644 --- a/ome_zarr/format.py +++ b/ome_zarr/format.py @@ -10,9 +10,7 @@ def format_from_version(version: str) -> "Format": - for fmt in format_implementations(): - # Support floating-point versions like `0.2` if isinstance(version, float): version = str(version) @@ -110,7 +108,7 @@ def validate_coordinate_transformations( self, ndim: int, nlevels: int, - coordinate_transformations: List[List[Dict[str, Any]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, ) -> Optional[List[List[Dict[str, Any]]]]: # pragma: no cover raise NotImplementedError() @@ -163,7 +161,7 @@ def validate_coordinate_transformations( self, ndim: int, nlevels: int, - coordinate_transformations: List[List[Dict[str, Any]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, ) -> None: return None @@ -258,7 +256,6 @@ def validate_well_dict( def generate_coordinate_transformations( self, shapes: List[tuple] ) -> Optional[List[List[Dict[str, Any]]]]: - data_shape = shapes[0] coordinate_transformations: List[List[Dict[str, Any]]] = [] # calculate minimal 'scale' transform based on pyramid dims @@ -273,7 +270,7 @@ def validate_coordinate_transformations( self, ndim: int, nlevels: int, - coordinate_transformations: List[List[Dict[str, Any]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, ) -> None: """ Validates that a list of dicts contains a 'scale' transformation diff --git a/ome_zarr/io.py b/ome_zarr/io.py index c3ad9de5..3d60ff91 100644 --- a/ome_zarr/io.py +++ b/ome_zarr/io.py @@ -30,7 +30,6 @@ class ZarrLocation: def __init__( self, path: Union[Path, str], mode: str = "r", fmt: Format = CurrentFormat() ) -> None: - LOGGER.debug("ZarrLocation.__init__ path: %s, fmt: %s", path, fmt.version) self.__fmt = fmt self.__mode = mode diff --git a/ome_zarr/reader.py b/ome_zarr/reader.py index edbcaa78..ccc4ea01 100644 --- a/ome_zarr/reader.py +++ b/ome_zarr/reader.py @@ -624,7 +624,6 @@ def __init__(self, zarr: ZarrLocation) -> None: def __call__(self) -> Iterator[Node]: node = Node(self.zarr, self) if node.specs: # Something has matched - LOGGER.debug("treating %s as ome-zarr", self.zarr) yield from self.descend(node) @@ -642,7 +641,6 @@ def __call__(self) -> Iterator[Node]: # yield nothing def descend(self, node: Node, depth: int = 0) -> Iterator[Node]: - for pre_node in node.pre_nodes: yield from self.descend(pre_node, depth + 1) diff --git a/ome_zarr/utils.py b/ome_zarr/utils.py index 01d80cd6..e55ceff5 100644 --- a/ome_zarr/utils.py +++ b/ome_zarr/utils.py @@ -27,7 +27,6 @@ def info(path: str, stats: bool = False) -> Iterator[Node]: assert zarr, f"not a zarr: {zarr}" reader = Reader(zarr) for node in reader(): - if not node.specs: print(f"not an ome-zarr node: {node}") continue @@ -73,7 +72,6 @@ def download(input_path: str, output_dir: str = ".") -> None: print(f"to {output_dir}") for path, node in sorted(zip(paths, nodes)): - target_path = output_path / Path(*path) target_path.mkdir(parents=True) diff --git a/ome_zarr/writer.py b/ome_zarr/writer.py index c1298a5a..c7ba7f7e 100644 --- a/ome_zarr/writer.py +++ b/ome_zarr/writer.py @@ -22,8 +22,8 @@ def _get_valid_axes( - ndim: int = None, - axes: Union[str, List[str], List[Dict[str, str]]] = None, + ndim: Optional[int] = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, fmt: Format = CurrentFormat(), ) -> Union[None, List[str], List[Dict[str, str]]]: """Returns list of axes valid for fmt.version or raise exception if invalid""" @@ -64,7 +64,6 @@ def _get_valid_axes( def _validate_well_images( images: List[Union[str, dict]], fmt: Format = CurrentFormat() ) -> List[dict]: - VALID_KEYS = [ "acquisition", "path", @@ -91,7 +90,6 @@ def _validate_well_images( def _validate_plate_acquisitions( acquisitions: List[Dict], fmt: Format = CurrentFormat() ) -> List[Dict]: - VALID_KEYS = [ "id", "name", @@ -117,7 +115,6 @@ def _validate_plate_rows_columns( rows_or_columns: List[str], fmt: Format = CurrentFormat(), ) -> List[dict]: - if len(set(rows_or_columns)) != len(rows_or_columns): raise ValueError(f"{rows_or_columns} must contain unique elements") validated_list = [] @@ -131,7 +128,6 @@ def _validate_plate_rows_columns( def _validate_datasets( datasets: List[dict], dims: int, fmt: Format = CurrentFormat() ) -> List[Dict]: - if datasets is None or len(datasets) == 0: raise ValueError("Empty datasets list") transformations = [] @@ -156,7 +152,6 @@ def _validate_plate_wells( columns: List[str], fmt: Format = CurrentFormat(), ) -> List[dict]: - validated_wells = [] if wells is None or len(wells) == 0: raise ValueError("Empty wells list") @@ -176,12 +171,12 @@ def _validate_plate_wells( def write_multiscale( pyramid: ListOfArrayLike, group: zarr.Group, - chunks: Union[Tuple[Any, ...], int] = None, + chunks: Optional[Union[Tuple[Any, ...], int]] = None, fmt: Format = CurrentFormat(), - axes: Union[str, List[str], List[Dict[str, str]]] = None, - coordinate_transformations: List[List[Dict[str, Any]]] = None, - storage_options: Union[JSONDict, List[JSONDict]] = None, - name: str = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, + storage_options: Optional[Union[JSONDict, List[JSONDict]]] = None, + name: Optional[str] = None, **metadata: Union[str, JSONDict, List[JSONDict]], ) -> None: """ @@ -277,8 +272,8 @@ def write_multiscales_metadata( group: zarr.Group, datasets: List[dict], fmt: Format = CurrentFormat(), - axes: Union[str, List[str], List[Dict[str, str]]] = None, - name: str = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, + name: Optional[str] = None, **metadata: Union[str, JSONDict, List[JSONDict]], ) -> None: """ @@ -334,9 +329,9 @@ def write_plate_metadata( columns: List[str], wells: List[Union[str, dict]], fmt: Format = CurrentFormat(), - acquisitions: List[dict] = None, - field_count: int = None, - name: str = None, + acquisitions: Optional[List[dict]] = None, + field_count: Optional[int] = None, + name: Optional[str] = None, ) -> None: """ Write the plate metadata in the group. @@ -405,11 +400,11 @@ def write_image( image: ArrayLike, group: zarr.Group, scaler: Scaler = Scaler(), - chunks: Union[Tuple[Any, ...], int] = None, + chunks: Optional[Union[Tuple[Any, ...], int]] = None, fmt: Format = CurrentFormat(), - axes: Union[str, List[str], List[Dict[str, str]]] = None, - coordinate_transformations: List[List[Dict[str, Any]]] = None, - storage_options: Union[JSONDict, List[JSONDict]] = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, + storage_options: Optional[Union[JSONDict, List[JSONDict]]] = None, **metadata: Union[str, JSONDict, List[JSONDict]], ) -> None: """Writes an image to the zarr store according to ome-zarr specification @@ -497,15 +492,14 @@ def _write_dask_image( image: da.Array, group: zarr.Group, scaler: Scaler = Scaler(), - chunks: Union[Tuple[Any, ...], int] = None, + chunks: Optional[Union[Tuple[Any, ...], int]] = None, fmt: Format = CurrentFormat(), - axes: Union[str, List[str], List[Dict[str, str]]] = None, - coordinate_transformations: List[List[Dict[str, Any]]] = None, - storage_options: Union[JSONDict, List[JSONDict]] = None, - name: str = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, + storage_options: Optional[Union[JSONDict, List[JSONDict]]] = None, + name: Optional[str] = None, **metadata: Union[str, JSONDict, List[JSONDict]], ) -> None: - if fmt.version in ("0.1", "0.2"): # v0.1 and v0.2 are strictly 5D shape_5d: Tuple[Any, ...] = (*(1,) * (5 - image.ndim), *image.shape) @@ -584,8 +578,8 @@ def _write_dask_image( def write_label_metadata( group: zarr.Group, name: str, - colors: List[JSONDict] = None, - properties: List[JSONDict] = None, + colors: Optional[List[JSONDict]] = None, + properties: Optional[List[JSONDict]] = None, fmt: Format = CurrentFormat(), **metadata: Union[List[JSONDict], JSONDict, str], ) -> None: @@ -633,12 +627,12 @@ def write_multiscale_labels( pyramid: List, group: zarr.Group, name: str, - chunks: Union[Tuple[Any, ...], int] = None, + chunks: Optional[Union[Tuple[Any, ...], int]] = None, fmt: Format = CurrentFormat(), - axes: Union[str, List[str], List[Dict[str, str]]] = None, - coordinate_transformations: List[List[Dict[str, Any]]] = None, - storage_options: Union[JSONDict, List[JSONDict]] = None, - label_metadata: JSONDict = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, + storage_options: Optional[Union[JSONDict, List[JSONDict]]] = None, + label_metadata: Optional[JSONDict] = None, **metadata: JSONDict, ) -> None: """ @@ -710,12 +704,12 @@ def write_labels( group: zarr.Group, name: str, scaler: Scaler = Scaler(), - chunks: Union[Tuple[Any, ...], int] = None, + chunks: Optional[Union[Tuple[Any, ...], int]] = None, fmt: Format = CurrentFormat(), - axes: Union[str, List[str], List[Dict[str, str]]] = None, - coordinate_transformations: List[List[Dict[str, Any]]] = None, - storage_options: Union[JSONDict, List[JSONDict]] = None, - label_metadata: JSONDict = None, + axes: Optional[Union[str, List[str], List[Dict[str, str]]]] = None, + coordinate_transformations: Optional[List[List[Dict[str, Any]]]] = None, + storage_options: Optional[Union[JSONDict, List[JSONDict]]] = None, + label_metadata: Optional[JSONDict] = None, **metadata: JSONDict, ) -> None: """ diff --git a/tests/test_writer.py b/tests/test_writer.py index 38b49d28..c3559c63 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -77,7 +77,6 @@ def scaler(self, request): def test_writer( self, shape, scaler, format_version, array_constructor, storage_options_list ): - data = self.create_data(shape) data = array_constructor(data) version = format_version() @@ -245,7 +244,6 @@ def test_default_compression(self): assert chunk_size < 4e6 def test_validate_coordinate_transforms(self): - fmt = FormatV04() transformations = [ @@ -287,7 +285,6 @@ def test_validate_coordinate_transforms(self): fmt.validate_coordinate_transformations(2, 2, scale_then_trans2) def test_dim_names(self): - v03 = FormatV03() # v0.3 MUST specify axes for 3D or 4D data @@ -335,7 +332,6 @@ def test_dim_names(self): ) def test_axes_dicts(self): - v04 = FormatV04() # ALL axes must specify 'name'