|
18 | 18 | from multiscale_spatial_image import to_multiscale |
19 | 19 | from multiscale_spatial_image.multiscale_spatial_image import MultiscaleSpatialImage |
20 | 20 | from multiscale_spatial_image.to_multiscale.to_multiscale import Methods |
21 | | -from pandas.api.types import is_categorical_dtype |
| 21 | +from pandas import CategoricalDtype |
22 | 22 | from shapely._geometry import GeometryType |
23 | 23 | from shapely.geometry import MultiPolygon, Point, Polygon |
24 | 24 | from shapely.geometry.collection import GeometryCollection |
@@ -470,7 +470,7 @@ def validate(cls, data: DaskDataFrame) -> None: |
470 | 470 | raise ValueError(f":attr:`dask.dataframe.core.DataFrame.attrs` does not contain `{cls.TRANSFORM_KEY}`.") |
471 | 471 | if cls.ATTRS_KEY in data.attrs and "feature_key" in data.attrs[cls.ATTRS_KEY]: |
472 | 472 | 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): |
474 | 474 | logger.info(f"Feature key `{feature_key}`could be of type `pd.Categorical`. Consider casting it.") |
475 | 475 |
|
476 | 476 | @singledispatchmethod |
@@ -624,7 +624,7 @@ def _add_metadata_and_validate( |
624 | 624 | # Here we are explicitly importing the categories |
625 | 625 | # but it is a convenient way to ensure that the categories are known. |
626 | 626 | # 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: |
628 | 628 | try: |
629 | 629 | data[c] = data[c].cat.set_categories(data[c].head(1).cat.categories) |
630 | 630 | except ValueError: |
@@ -729,7 +729,7 @@ def parse( |
729 | 729 | region_: list[str] = region if isinstance(region, list) else [region] |
730 | 730 | if not adata.obs[region_key].isin(region_).all(): |
731 | 731 | 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): |
733 | 733 | warnings.warn( |
734 | 734 | f"Converting `{cls.REGION_KEY_KEY}: {region_key}` to categorical dtype.", UserWarning, stacklevel=2 |
735 | 735 | ) |
|
0 commit comments