Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (scverse#685)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.5.7 → v0.6.1](astral-sh/ruff-pre-commit@v0.5.7...v0.6.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update pre-commit

* fix precommit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: giovp <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and giovp authored Aug 23, 2024
1 parent a9ac788 commit b80b364
Show file tree
Hide file tree
Showing 29 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
additional_dependencies: [numpy, types-requests]
exclude: tests/|docs/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.6.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
2 changes: 1 addition & 1 deletion src/spatialdata/_core/operations/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def rasterize(
element_name = data if isinstance(data, str) else None
kwargs = {"sdata": sdata, "element_name": element_name} if element_name is not None else {"element": data}
values = get_values(value_key, table_name=table_name, **kwargs).iloc[:, 0] # type: ignore[arg-type, union-attr]
max_index = np.max(values.index)
max_index: int = np.max(values.index)
assigner = np.zeros(max_index + 1, dtype=values.dtype)
assigner[values.index] = values
# call-arg is ignored because model is never TableModel (the error is that the transformation param is not
Expand Down
6 changes: 4 additions & 2 deletions src/spatialdata/_core/operations/rasterize_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from xarray import DataArray

from spatialdata._core.query.relational_query import get_values
from spatialdata._types import ArrayLike
from spatialdata.models import Image2DModel, get_table_keys
from spatialdata.transformations import Affine, Sequence, get_transformation

Expand Down Expand Up @@ -113,8 +114,9 @@ def rasterize_bins(
if value_key is None:
shape = (n_rows, n_cols)

def channel_rasterization(block_id: tuple[int, int, int] | None) -> np.ndarray: # type: ignore[type-arg]
image = np.zeros((1, *shape), dtype=dtype)
def channel_rasterization(block_id: tuple[int, int, int] | None) -> ArrayLike:

image: ArrayLike = np.zeros((1, *shape), dtype=dtype)

if block_id is None:
return image
Expand Down
4 changes: 2 additions & 2 deletions src/spatialdata/_core/operations/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def _transform_raster(
v: ArrayLike = np.hstack(c_channel + [binary, np.ones(len(binary)).reshape((-1, 1))])
matrix = transformation.to_affine_matrix(input_axes=axes, output_axes=axes)
inverse_matrix = transformation.inverse().to_affine_matrix(input_axes=axes, output_axes=axes)
new_v = (matrix @ v.T).T
new_v: ArrayLike = (matrix @ v.T).T
c_shape: tuple[int, ...]
c_shape = (data.shape[0],) if "c" in axes else ()
new_spatial_shape = tuple(
int(np.max(new_v[:, i]) - np.min(new_v[:, i])) for i in range(len(c_shape), n_spatial_dims + len(c_shape))
int(np.max(new_v[:, i]) - np.min(new_v[:, i])) for i in range(len(c_shape), n_spatial_dims + len(c_shape)) # type: ignore[operator]
)
output_shape = c_shape + new_spatial_shape
translation_vector = np.min(new_v[:, :-1], axis=0)
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from shapely import linearrings, polygons
from shapely.geometry import MultiPolygon, Point, Polygon
from skimage import data
from xarray import DataArray

from spatialdata._core._deepcopy import deepcopy
from spatialdata._core.spatialdata import SpatialData
from spatialdata._types import ArrayLike
Expand All @@ -34,7 +36,6 @@
ShapesModel,
TableModel,
)
from xarray import DataArray

SEED = 0
RNG = default_rng(seed=SEED)
Expand Down
1 change: 1 addition & 0 deletions tests/core/operations/test_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from anndata.tests.helpers import assert_equal
from geopandas import GeoDataFrame
from numpy.random import default_rng

from spatialdata import aggregate, to_polygons
from spatialdata._core._deepcopy import deepcopy as _deepcopy
from spatialdata._core.spatialdata import SpatialData
Expand Down
3 changes: 2 additions & 1 deletion tests/core/operations/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import numpy as np
import pytest
from xarray import DataArray

from spatialdata._core.operations.map import map_raster
from spatialdata.transformations import Translation, get_transformation, set_transformation
from xarray import DataArray


def _multiply(arr, parameter=10):
Expand Down
4 changes: 2 additions & 2 deletions tests/core/operations/test_rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from multiscale_spatial_image import MultiscaleSpatialImage
from shapely import MultiPolygon, box
from spatial_image import SpatialImage
from xarray import DataArray

from spatialdata import SpatialData, get_extent
from spatialdata._core.operations.rasterize import rasterize
from spatialdata._core.query.relational_query import get_element_instances
from spatialdata._io._utils import _iter_multiscale
from spatialdata.models import PointsModel, ShapesModel, TableModel, get_axes_names
from spatialdata.models._utils import get_spatial_axes
from spatialdata.transformations import MapAxis
from xarray import DataArray

from tests.conftest import _get_images, _get_labels


Expand Down
1 change: 1 addition & 0 deletions tests/core/operations/test_rasterize_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandas import DataFrame
from scipy.sparse import csr_matrix
from shapely.geometry import Polygon

from spatialdata._core.data_extent import are_extents_equal, get_extent
from spatialdata._core.operations.rasterize_bins import rasterize_bins
from spatialdata._core.spatialdata import SpatialData
Expand Down
2 changes: 1 addition & 1 deletion tests/core/operations/test_spatialdata_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pytest
from anndata import AnnData

from spatialdata._core.concatenate import _concatenate_tables, concatenate
from spatialdata._core.data_extent import are_extents_equal, get_extent
from spatialdata._core.operations._utils import transform_to_data_extent
Expand All @@ -21,7 +22,6 @@
Sequence,
Translation,
)

from tests.conftest import _get_table


Expand Down
3 changes: 2 additions & 1 deletion tests/core/operations/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
from datatree import DataTree
from geopandas.testing import geom_almost_equals
from xarray import DataArray

from spatialdata import transform
from spatialdata._core.data_extent import are_extents_equal, get_extent
from spatialdata._core.spatialdata import SpatialData
Expand All @@ -28,7 +30,6 @@
Sequence,
Translation,
)
from xarray import DataArray


class TestElementsTransform:
Expand Down
1 change: 1 addition & 0 deletions tests/core/operations/test_vectorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from geopandas import GeoDataFrame
from shapely import MultiPoint, Point

from spatialdata._core.operations.vectorize import to_circles, to_polygons
from spatialdata.datasets import blobs
from spatialdata.models.models import ShapesModel
Expand Down
1 change: 1 addition & 0 deletions tests/core/query/test_relational_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pandas as pd
import pytest
from anndata import AnnData

from spatialdata import get_values, match_table_to_element
from spatialdata._core.query.relational_query import (
_locate_value,
Expand Down
4 changes: 2 additions & 2 deletions tests/core/query/test_spatial_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from datatree import DataTree
from geopandas import GeoDataFrame
from shapely import MultiPolygon, Point, Polygon
from xarray import DataArray

from spatialdata._core.data_extent import get_extent
from spatialdata._core.query.spatial_query import (
BaseSpatialRequest,
Expand All @@ -30,8 +32,6 @@
)
from spatialdata.testing import assert_spatial_data_objects_are_identical
from spatialdata.transformations import Identity, MapAxis, set_transformation
from xarray import DataArray

from tests.conftest import _make_points, _make_squares


Expand Down
1 change: 1 addition & 0 deletions tests/core/test_centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from anndata import AnnData
from numpy.random import default_rng

from spatialdata._core.centroids import get_centroids
from spatialdata._core.query.relational_query import get_element_instances
from spatialdata.models import Labels2DModel, Labels3DModel, PointsModel, TableModel, get_axes_names
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_data_extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from geopandas import GeoDataFrame
from numpy.random import default_rng
from shapely.geometry import MultiPolygon, Point, Polygon

from spatialdata import SpatialData, get_extent, transform
from spatialdata._core._deepcopy import deepcopy as _deepcopy
from spatialdata.datasets import blobs
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_deepcopy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pandas.testing import assert_frame_equal

from spatialdata._core._deepcopy import deepcopy as _deepcopy
from spatialdata.testing import assert_spatial_data_objects_are_identical

Expand Down
1 change: 1 addition & 0 deletions tests/dataloader/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from spatialdata.dataloader import ImageTilesDataset
from spatialdata.datasets import blobs_annotating_element

Expand Down
1 change: 1 addition & 0 deletions tests/io/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from shapely import GeometryType

from spatialdata._io.format import CurrentPointsFormat, CurrentShapesFormat, ShapesFormatV01
from spatialdata.models import PointsModel, ShapesModel

Expand Down
1 change: 1 addition & 0 deletions tests/io/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile

import pytest

from spatialdata import SpatialData, read_zarr
from spatialdata._io._utils import _is_element_self_contained
from spatialdata._logging import logger
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_multi_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pytest
from anndata import AnnData
from anndata.tests.helpers import assert_equal

from spatialdata import SpatialData, concatenate
from spatialdata.models import TableModel

from tests.conftest import _get_shapes, _get_table

# notes on paths: https://github.com/orgs/scverse/projects/17/views/1?pane=issue&itemId=44066734
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from anndata import AnnData
from numpy.random import default_rng

from spatialdata import SpatialData, deepcopy, read_zarr
from spatialdata._io._utils import _are_directories_identical, get_dask_backing_files
from spatialdata.datasets import blobs
Expand All @@ -19,7 +20,6 @@
set_transformation,
)
from spatialdata.transformations.transformations import Identity, Scale

from tests.conftest import _get_images, _get_labels, _get_points, _get_shapes

RNG = default_rng(0)
Expand Down
1 change: 1 addition & 0 deletions tests/io/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile

import dask.dataframe as dd

from spatialdata import read_zarr
from spatialdata._io._utils import get_dask_backing_files

Expand Down
4 changes: 2 additions & 2 deletions tests/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from shapely.geometry import MultiPolygon, Point, Polygon
from shapely.io import to_ragged_array
from spatial_image import to_spatial_image
from xarray import DataArray

from spatialdata._core.spatialdata import SpatialData
from spatialdata._types import ArrayLike
from spatialdata.models._utils import (
Expand Down Expand Up @@ -51,8 +53,6 @@
set_transformation,
)
from spatialdata.transformations.transformations import Identity, Scale
from xarray import DataArray

from tests.conftest import (
MULTIPOLYGON_PATH,
POINT_PATH,
Expand Down
1 change: 1 addition & 0 deletions tests/transformations/ngff/test_ngff_coordinate_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

import pytest

from spatialdata.transformations.ngff.ngff_coordinate_system import (
NgffAxis,
NgffCoordinateSystem,
Expand Down
2 changes: 1 addition & 1 deletion tests/transformations/ngff/test_ngff_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import pytest

from spatialdata._types import ArrayLike
from spatialdata.models import C, X, Y, Z
from spatialdata.transformations.ngff._utils import get_default_coordinate_system
Expand All @@ -19,7 +20,6 @@
NgffSequence,
NgffTranslation,
)

from tests.transformations.ngff.conftest import (
c_cs,
cyx_cs,
Expand Down
3 changes: 2 additions & 1 deletion tests/transformations/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import numpy as np
import pytest
import xarray.testing
from xarray import DataArray

from spatialdata import transform
from spatialdata.datasets import blobs
from spatialdata.models import Image2DModel, PointsModel
Expand Down Expand Up @@ -32,7 +34,6 @@
_decompose_transformation,
_get_affine_for_element,
)
from xarray import DataArray


def test_identity():
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/test_element_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import pytest
import xarray
from datatree import DataTree
from xarray import DataArray

from spatialdata._utils import unpad_raster
from spatialdata.models import get_model
from spatialdata.transformations import Affine
from xarray import DataArray


def _pad_raster(data: DataArray, axes: tuple[str, ...]) -> DataArray:
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pytest
from datatree import DataTree
from xarray import DataArray

from spatialdata import SpatialData, deepcopy
from spatialdata.models import (
Image2DModel,
Expand All @@ -16,7 +18,6 @@
)
from spatialdata.testing import assert_elements_are_identical, assert_spatial_data_objects_are_identical
from spatialdata.transformations import Scale, set_transformation
from xarray import DataArray

scale = Scale([1.0], axes=("x",))

Expand Down

0 comments on commit b80b364

Please sign in to comment.