Skip to content

Commit

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

updates:
- [github.com/pre-commit/mirrors-mypy: v1.11.2 → v1.13.0](pre-commit/mirrors-mypy@v1.11.2...v1.13.0)
- [github.com/psf/black: 24.8.0 → 24.10.0](psf/black@24.8.0...24.10.0)
- [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0)
- [github.com/asottile/blacken-docs: 1.18.0 → 1.19.1](adamchainz/blacken-docs@1.18.0...1.19.1)
- [github.com/astral-sh/ruff-pre-commit: v0.6.8 → v0.8.3](astral-sh/ruff-pre-commit@v0.6.8...v0.8.3)

* fix precommit

* fix pre-commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Luca Marconato <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and LucaMarconato authored Dec 17, 2024
1 parent 776c26e commit 802b812
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ default_stages:
minimum_pre_commit_version: 2.9.3
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [numpy>=1.23]
exclude: docs
- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black
additional_dependencies: [toml]
Expand All @@ -22,7 +22,7 @@ repos:
hooks:
- id: prettier
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: detect-private-key
- id: check-merge-conflict
Expand All @@ -45,11 +45,11 @@ repos:
- id: check-toml
- id: requirements-txt-fixer
- repo: https://github.com/asottile/blacken-docs
rev: 1.18.0
rev: 1.19.1
hooks:
- id: blacken-docs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
rev: v0.8.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
4 changes: 4 additions & 0 deletions src/napari_spatialdata/_scatterwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ def clear_hover_highlight(self) -> None:
def use_auto_range(self) -> None:
"""Default display of the graph."""
if self.lut is not None:
assert self.color_vec is not None
color_min = self.color_vec.min()
color_max = self.color_vec.max()

Expand Down Expand Up @@ -803,6 +804,7 @@ def create_lut_hist(self) -> pg.HistogramLUTItem:
st["ticksVisible"] = False
lut.gradient.restoreState(st)

assert self.color_vec is not None
y, x = np.histogram(self.color_vec, bins="auto")
lut.plot.setData(
np.concatenate([[np.min(self.color_vec)], (x[:-1] + x[1:]) / 2, [np.max(self.color_vec)]]),
Expand Down Expand Up @@ -867,13 +869,15 @@ def get_brushes(self, event: Any = None) -> list[QColor] | None:
# for discrete data
if self.discrete_color_widget is not None:

assert self.color_vec is not None
return [pg.mkBrush(*x) for x in self.discrete_color_widget.palette.map(self.color_vec + 1) * 255]

# for continuos data
if self.lut is not None:

level_min, level_max = self.lut.getLevels()

assert self.color_vec is not None
data = np.clip(self.color_vec, level_min, level_max)
data = (data - level_min) / (level_max - level_min)

Expand Down
4 changes: 2 additions & 2 deletions src/napari_spatialdata/_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def viewer(self) -> napari.Viewer:
@property
def model(self) -> DataModel:
""":mod:`napari` viewer."""
return self._model # type: ignore[no-any-return]
return self._model


class QtAdataViewWidget(QWidget):
Expand Down Expand Up @@ -681,7 +681,7 @@ def viewer(self) -> napari.Viewer:
@property
def model(self) -> DataModel:
""":mod:`napari` viewer."""
return self._model # type: ignore[no-any-return]
return self._model

@property
def layernames(self) -> frozenset[str]:
Expand Down
4 changes: 2 additions & 2 deletions src/napari_spatialdata/_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ def inherit_metadata(self, layers: list[Layer], ref_layer: Layer) -> None:

def _get_table_data(
self, sdata: SpatialData, element_name: str
) -> tuple[AnnData | None, str | None, list[str | None]]:
table_names = list(get_element_annotators(sdata, element_name))
) -> tuple[AnnData | None, str | None, list[str] | None]:
table_names: list[str] = list(get_element_annotators(sdata, element_name))
table_name = table_names[0] if len(table_names) > 0 else None
adata = _get_init_metadata_adata(sdata, table_name, element_name)
return adata, table_name, table_names
Expand Down
12 changes: 8 additions & 4 deletions src/napari_spatialdata/_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ def _get_points_properties(self, vec: ArrayLike | pd.Series, **kwargs: Any) -> d
@_get_points_properties.register(pd.Series)
def _(self, vec: pd.Series, **kwargs: Any) -> dict[str, Any]:
layer = kwargs.pop("layer", None)
layer_meta = self.model.layer.metadata if self.model.layer is not None else None
element_indices = pd.Series(layer_meta["indices"], name="element_indices")
layer_metadata = self.model.layer.metadata if self.model.layer is not None else None
if layer_metadata is None:
raise ValueError("Layer metadata is not available.")
element_indices = pd.Series(layer_metadata["indices"], name="element_indices")
if isinstance(layer, Labels):
element_indices = element_indices[element_indices != 0]
# When merging if the row is not present in the other table it will be nan so we can give it a default color
Expand Down Expand Up @@ -276,8 +278,10 @@ def _(self, vec: ArrayLike, **kwargs: Any) -> dict[str, Any]:
else:
instance_key_col = self.model.adata.obs[self.model.instance_key]
vec = pd.Series(vec, name="vec", index=instance_key_col)
layer_meta = self.model.layer.metadata if self.model.layer is not None else None
element_indices = pd.Series(layer_meta["indices"], name="element_indices")
layer_metadata = self.model.layer.metadata if self.model.layer is not None else None
if layer_metadata is None:
raise ValueError("Layer metadata is not available.")
element_indices = pd.Series(layer_metadata["indices"], name="element_indices")
if isinstance(layer, Labels):
vec = vec.drop(index=0) if 0 in vec.index else vec
# element_indices = element_indices[element_indices != 0]
Expand Down
2 changes: 1 addition & 1 deletion src/napari_spatialdata/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def get_elements_meta_mapping(
return elements, name_to_add


def _get_init_metadata_adata(sdata: SpatialData, table_name: str, element_name: str) -> None | AnnData:
def _get_init_metadata_adata(sdata: SpatialData, table_name: str | None, element_name: str) -> None | AnnData:
"""
Retrieve AnnData to be used in layer metadata.
Expand Down

0 comments on commit 802b812

Please sign in to comment.