Skip to content

support for datatree from xarray #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ["3.9", "3.10"]
python: ["3.10", "3.12"]
os: [ubuntu-latest]

env:
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
pip install pytest-cov
- name: Install dependencies
run: |
pip install --pre -e ".[dev,test]"
pip install --pre -e ".[dev,test,pre]"
- name: Test
env:
MPLBACKEND: agg
Expand Down
4 changes: 2 additions & 2 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.9
python_version = 3.10
plugins = numpy.typing.mypy_plugin

ignore_errors = False
Expand All @@ -25,4 +25,4 @@ no_warn_no_return = True

show_error_codes = True
show_column_numbers = True
error_summary = True
error_summary = True
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ maintainers = [
urls.Documentation = "https://spatialdata.scverse.org/projects/plot/en/latest/index.html"
urls.Source = "https://github.com/scverse/spatialdata-plot.git"
urls.Home-page = "https://github.com/scverse/spatialdata-plot.git"
requires-python = ">=3.9"
requires-python = ">=3.10"
dynamic= [
"version" # allow version to be set by git tags
]
Expand Down Expand Up @@ -75,7 +75,7 @@ filterwarnings = [

[tool.black]
line-length = 120
target-version = ['py39']
target-version = ['py310']
include = '\.pyi?$'
exclude = '''
(
Expand Down Expand Up @@ -158,7 +158,7 @@ lint.select = [
"PGH", # pygrep-hooks
]
lint.unfixable = ["B", "UP", "C4", "BLE", "T20", "RET"]
target-version = "py39"
target-version = "py310"
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D", "PT", "B024"]
"*/__init__.py" = ["F401", "D104", "D107", "E402"]
Expand Down
9 changes: 4 additions & 5 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import OrderedDict
from copy import deepcopy
from pathlib import Path
from typing import Any, Union
from typing import Any

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -14,14 +14,13 @@
import spatialdata as sd
from anndata import AnnData
from dask.dataframe import DataFrame as DaskDataFrame
from datatree import DataTree
from geopandas import GeoDataFrame
from matplotlib.axes import Axes
from matplotlib.colors import Colormap, Normalize
from matplotlib.figure import Figure
from spatialdata import get_extent
from spatialdata._utils import _deprecation_alias
from xarray import DataArray
from xarray import DataArray, DataTree

from spatialdata_plot._accessor import register_spatial_data_accessor
from spatialdata_plot.pl.render import (
Expand Down Expand Up @@ -62,7 +61,7 @@
# replace with
# from spatialdata._types import ColorLike
# once https://github.com/scverse/spatialdata/pull/689/ is in a release
ColorLike = Union[tuple[float, ...], str]
ColorLike = tuple[float, ...] | str


@register_spatial_data_accessor("pl")
Expand Down Expand Up @@ -950,7 +949,7 @@ def show(
if wanted_labels_on_this_cs:
if (table := params_copy.table_name) is not None:
colors = sc.get.obs_df(sdata[table], params_copy.color)
if isinstance(colors.dtype, pd.CategoricalDtype):
if isinstance(colors[params_copy.color].dtype, pd.CategoricalDtype):
_maybe_set_colors(
source=sdata[table],
target=sdata[table],
Expand Down
7 changes: 3 additions & 4 deletions src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import warnings
from collections import abc
from copy import copy
from typing import Union

import dask
import datashader as ds
Expand All @@ -15,7 +14,6 @@
import scanpy as sc
import spatialdata as sd
from anndata import AnnData
from datatree import DataTree
from matplotlib.cm import ScalarMappable
from matplotlib.colors import ListedColormap, Normalize
from scanpy._settings import settings as sc_settings
Expand All @@ -24,6 +22,7 @@
from spatialdata.transformations import (
set_transformation,
)
from xarray import DataTree

from spatialdata_plot._logging import logger
from spatialdata_plot.pl.render_params import (
Expand Down Expand Up @@ -56,7 +55,7 @@
to_hex,
)

_Normalize = Union[Normalize, abc.Sequence[Normalize]]
_Normalize = Normalize | abc.Sequence[Normalize]


def _render_shapes(
Expand Down Expand Up @@ -442,7 +441,7 @@ def _render_points(
if col_for_color is not None:
cols = sc.get.obs_df(adata, col_for_color)
# maybe set color based on type
if isinstance(cols.dtype, pd.CategoricalDtype):
if isinstance(cols[col_for_color].dtype, pd.CategoricalDtype):
_maybe_set_colors(
source=adata,
target=adata,
Expand Down
4 changes: 2 additions & 2 deletions src/spatialdata_plot/pl/render_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections.abc import Callable, Sequence
from dataclasses import dataclass
from typing import Literal, Union
from typing import Literal

from matplotlib.axes import Axes
from matplotlib.colors import Colormap, ListedColormap, Normalize
Expand All @@ -14,7 +14,7 @@
# replace with
# from spatialdata._types import ColorLike
# once https://github.com/scverse/spatialdata/pull/689/ is in a release
ColorLike = Union[tuple[float, ...], str]
ColorLike = tuple[float, ...] | str


@dataclass
Expand Down
Loading
Loading