Skip to content

Commit 63e761d

Browse files
committed
fix tests and docs and remove
1 parent fa539f5 commit 63e761d

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎src/spatialdata/dataloader/datasets.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ def _get_tile_coords(
375375

376376
# get extent, first by checking shape defaults, then by using the `tile_dim_in_units`
377377
if tile_dim_in_units is None:
378-
if elem.iloc[0][0].geom_type == "Point":
378+
if elem.iloc[0, 0].geom_type == "Point":
379379
extent = elem[ShapesModel.RADIUS_KEY].values * tile_scale
380-
elif elem.iloc[0][0].geom_type in ["Polygon", "MultiPolygon"]:
380+
elif elem.iloc[0, 0].geom_type in ["Polygon", "MultiPolygon"]:
381381
extent = elem[ShapesModel.GEOMETRY_KEY].length * tile_scale
382382
else:
383383
raise ValueError("Only point and polygon shapes are supported.")

‎src/spatialdata/models/models.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from multiscale_spatial_image import to_multiscale
1919
from multiscale_spatial_image.multiscale_spatial_image import MultiscaleSpatialImage
2020
from multiscale_spatial_image.to_multiscale.to_multiscale import Methods
21-
from pandas.api.types import is_categorical_dtype
21+
from pandas import CategoricalDtype
2222
from shapely._geometry import GeometryType
2323
from shapely.geometry import MultiPolygon, Point, Polygon
2424
from shapely.geometry.collection import GeometryCollection
@@ -470,7 +470,7 @@ def validate(cls, data: DaskDataFrame) -> None:
470470
raise ValueError(f":attr:`dask.dataframe.core.DataFrame.attrs` does not contain `{cls.TRANSFORM_KEY}`.")
471471
if cls.ATTRS_KEY in data.attrs and "feature_key" in data.attrs[cls.ATTRS_KEY]:
472472
feature_key = data.attrs[cls.ATTRS_KEY][cls.FEATURE_KEY]
473-
if not is_categorical_dtype(data[feature_key]):
473+
if not isinstance(data[feature_key], CategoricalDtype):
474474
logger.info(f"Feature key `{feature_key}`could be of type `pd.Categorical`. Consider casting it.")
475475

476476
@singledispatchmethod
@@ -624,7 +624,7 @@ def _add_metadata_and_validate(
624624
# Here we are explicitly importing the categories
625625
# but it is a convenient way to ensure that the categories are known.
626626
# It also just changes the state of the series, so it is not a big deal.
627-
if is_categorical_dtype(data[c]) and not data[c].cat.known:
627+
if isinstance(data[c], CategoricalDtype) and not data[c].cat.known:
628628
try:
629629
data[c] = data[c].cat.set_categories(data[c].head(1).cat.categories)
630630
except ValueError:
@@ -729,7 +729,7 @@ def parse(
729729
region_: list[str] = region if isinstance(region, list) else [region]
730730
if not adata.obs[region_key].isin(region_).all():
731731
raise ValueError(f"`adata.obs[{region_key}]` values do not match with `{cls.REGION_KEY}` values.")
732-
if not is_categorical_dtype(adata.obs[region_key]):
732+
if not isinstance(adata.obs[region_key], CategoricalDtype):
733733
warnings.warn(
734734
f"Converting `{cls.REGION_KEY_KEY}: {region_key}` to categorical dtype.", UserWarning, stacklevel=2
735735
)

‎tests/dataloader/test_datasets.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ def test_default(self, sdata_blobs, regions_element, raster):
6060
if raster:
6161
assert tile.shape == (3, 329, 329)
6262
else:
63-
assert tile.shape == (3, 164, 164)
63+
assert tile.shape == (3, 165, 164)
6464
else:
6565
raise ValueError(f"Unexpected regions_element: {regions_element}")
66+
6667
# extent has units in pixel so should be the same as tile shape
6768
if raster:
6869
assert round(ds.tiles_coords.extent.unique()[0] * 2) == tile.shape[1]
6970
else:
70-
assert int(ds.tiles_coords.extent.unique()[0]) == tile.shape[1]
71+
if regions_element != "blobs_multipolygons":
72+
assert int(ds.tiles_coords.extent.unique()[0]) == tile.shape[1]
73+
else:
74+
assert int(ds.tiles_coords.extent.unique()[0]) + 1 == tile.shape[1]
7175
assert np.all(sdata_tile.table.obs.columns == ds.sdata.table.obs.columns)
7276
assert list(sdata_tile.images.keys())[0] == "blobs_image"
7377

@@ -88,11 +92,14 @@ def test_return_annot(self, sdata_blobs, regions_element, return_annot):
8892
elif regions_element == "blobs_polygons":
8993
assert tile.shape == (3, 82, 82)
9094
elif regions_element == "blobs_multipolygons":
91-
assert tile.shape == (3, 164, 164)
95+
assert tile.shape == (3, 165, 164)
9296
else:
9397
raise ValueError(f"Unexpected regions_element: {regions_element}")
9498
# extent has units in pixel so should be the same as tile shape
95-
assert int(ds.tiles_coords.extent.unique()[0]) == tile.shape[1]
99+
if regions_element != "blobs_multipolygons":
100+
assert int(ds.tiles_coords.extent.unique()[0]) == tile.shape[1]
101+
else:
102+
assert round(ds.tiles_coords.extent.unique()[0]) + 1 == tile.shape[1]
96103
return_annot = [return_annot] if isinstance(return_annot, str) else return_annot
97104
assert annot.shape[1] == len(return_annot)
98105

0 commit comments

Comments
 (0)