Skip to content

Commit

Permalink
Update pre-commit linters and new lint errors
Browse files Browse the repository at this point in the history
* Black format changes
* Remove call to deprecated `pd.api.types.is_categorical_dtype`
* Update pyproject.toml ruff syntax
  • Loading branch information
jp-dark committed Jul 31, 2024
1 parent 23ae756 commit 402b2bc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
# Start with the basic pre-commit hooks

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -14,7 +14,7 @@ repos:
# Then others in alphabetical order:

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.5.5
hooks:
- id: ruff

Expand All @@ -23,7 +23,7 @@ repos:
# the entire dependency list here we only install `attrs`. It will catch
# a useful subset of errors but does not replace a full mypy run
# (either locally or in CI).
rev: v1.5.1
rev: v1.11.1
hooks:
- id: mypy
additional_dependencies: [attrs]
Expand All @@ -36,6 +36,6 @@ repos:
# with `types_or` in the future.

- repo: https://github.com/psf/black
rev: "23.9.1"
rev: "24.4.2"
hooks:
- id: black
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ urls = { repository = "https://github.com/single-cell-data/SOMA.git" }
classifiers = ["License :: OSI Approved :: MIT License"]

[project.optional-dependencies]
dev = ["black", "isort", "mypy~=1.0", "ruff"]
dev = ["black", "isort", "mypy~=1.0", "ruff", "pandas-stubs"]

[tool.setuptools]
packages.find.where = ["python-spec/src"]
Expand All @@ -42,9 +42,9 @@ write_to = "python-spec/src/somacore/_version.py"
tag_regex = '^python-(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$'

[tool.ruff]
extend-select = ["I"]
lint.extend-select = ["I"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-single-line = true
known-first-party = ["somacore"]
single-line-exclusions = ["typing", "typing_extensions"]
Expand Down
6 changes: 2 additions & 4 deletions python-spec/src/somacore/_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ def __set_name__(self, owner: Type[_Coll], name: str) -> None:
self.item_name = name

@overload
def __get__(self, inst: None, owner: Type[_Coll]) -> "item[_T]":
...
def __get__(self, inst: None, owner: Type[_Coll]) -> "item[_T]": ...

@overload
def __get__(self, inst: _Coll, owner: Type[_Coll]) -> _T:
...
def __get__(self, inst: _Coll, owner: Type[_Coll]) -> _T: ...

def __get__(self, inst: Optional[_Coll], owner: Type[_Coll]) -> Union["item", _T]:
del owner # unused
Expand Down
6 changes: 2 additions & 4 deletions python-spec/src/somacore/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def add_new_collection(
*,
uri: Optional[str] = ...,
platform_config: Optional[options.PlatformConfig] = ...,
) -> "Collection":
...
) -> "Collection": ...

@overload
@abc.abstractmethod
Expand All @@ -74,8 +73,7 @@ def add_new_collection(
*,
uri: Optional[str] = ...,
platform_config: Optional[options.PlatformConfig] = ...,
) -> _CT:
...
) -> _CT: ...

@abc.abstractmethod
def add_new_collection(
Expand Down
30 changes: 12 additions & 18 deletions python-spec/src/somacore/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ def to_anndata(
# Drop unused categories on axis dataframes if requested
if drop_levels:
for name in ad.obs:
if pd.api.types.is_categorical_dtype(ad.obs[name]):
if isinstance(ad.obs[name], pd.CategoricalDtype):
ad.obs[name] = ad.obs[name].cat.remove_unused_categories()
for name in ad.var:
if pd.api.types.is_categorical_dtype(ad.var[name]):
if isinstance(ad.obs[name], pd.CategoricalDtype):
ad.var[name] = ad.var[name].cat.remove_unused_categories()

return ad
Expand Down Expand Up @@ -672,18 +672,17 @@ def value(self) -> Literal["obs", "var"]:
return super().value

@overload
def getattr_from(self, __source: "_HasObsVar[_T]") -> "_T":
...
def getattr_from(self, __source: "_HasObsVar[_T]") -> "_T": ...

@overload
def getattr_from(
self, __source: Any, *, pre: Literal[""], suf: Literal[""]
) -> object:
...
) -> object: ...

@overload
def getattr_from(self, __source: Any, *, pre: str = ..., suf: str = ...) -> object:
...
def getattr_from(
self, __source: Any, *, pre: str = ..., suf: str = ...
) -> object: ...

def getattr_from(self, __source: Any, *, pre: str = "", suf: str = "") -> object:
"""Equivalent to ``something.<pre><obs/var><suf>``."""
Expand Down Expand Up @@ -820,16 +819,13 @@ class _Experimentish(Protocol):
"""The API we need from an Experiment."""

@property
def ms(self) -> Mapping[str, measurement.Measurement]:
...
def ms(self) -> Mapping[str, measurement.Measurement]: ...

@property
def obs(self) -> data.DataFrame:
...
def obs(self) -> data.DataFrame: ...

@property
def context(self) -> Optional[base_types.ContextBase]:
...
def context(self) -> Optional[base_types.ContextBase]: ...


class _HasObsVar(Protocol[_T_co]):
Expand All @@ -839,9 +835,7 @@ class _HasObsVar(Protocol[_T_co]):
"""

@property
def obs(self) -> _T_co:
...
def obs(self) -> _T_co: ...

@property
def var(self) -> _T_co:
...
def var(self) -> _T_co: ...
9 changes: 3 additions & 6 deletions python-spec/src/somacore/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ class Slice(Protocol[_T_co]):
# invariant rather than covariant.

@property
def start(self) -> Optional[_T_co]:
...
def start(self) -> Optional[_T_co]: ...

@property
def stop(self) -> Optional[_T_co]:
...
def stop(self) -> Optional[_T_co]: ...

@property
def step(self) -> Optional[_T_co]:
...
def step(self) -> Optional[_T_co]: ...

if sys.version_info < (3, 10) and not TYPE_CHECKING:
# Python 3.9 and below have a bug where any Protocol with an @property
Expand Down

0 comments on commit 402b2bc

Please sign in to comment.