Skip to content
Open
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.6
rev: v0.16.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if __name__ == "__main__":
try:
setup(use_scm_version={"version_scheme": "no-guess-dev"})
except: # noqa
except:
print(
"\n\nAn error occurred while building the project, "
"please ensure you have the most updated version of setuptools, "
Expand Down
13 changes: 7 additions & 6 deletions src/biocutils/BooleanList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Iterable, Optional, Sequence, Union
from collections.abc import Iterable, Sequence
from typing import Any

from .NamedList import NamedList
from .Names import Names
Expand All @@ -23,7 +24,7 @@ def __init__(self, data: Sequence) -> None:
"""
self._data = data

def __getitem__(self, index: int) -> Optional[bool]:
def __getitem__(self, index: int) -> bool | None:
"""Get an item and coerce it to boolean.

Args:
Expand All @@ -46,8 +47,8 @@ class BooleanList(NamedList):

def __init__(
self,
data: Optional[Sequence] = None,
names: Optional[Names] = None,
data: Sequence | None = None,
names: Names | None = None,
_validate: bool = True,
):
"""
Expand Down Expand Up @@ -76,15 +77,15 @@ def __init__(

super().__init__(data, names, _validate=_validate)

def set_value(self, index: Union[int, str], value: Any, in_place: bool = False) -> BooleanList:
def set_value(self, index: int | str, value: Any, in_place: bool = False) -> BooleanList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a boolean."""
return super().set_value(index, _coerce_to_bool(value), in_place=in_place)

def set_slice(self, index: SubscriptTypes, value: Sequence, in_place: bool = False) -> BooleanList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to booleans."""
return super().set_slice(index, _SubscriptCoercer(value), in_place=in_place)

def safe_insert(self, index: Union[int, str], value: Any, in_place: bool = False) -> BooleanList:
def safe_insert(self, index: int | str, value: Any, in_place: bool = False) -> BooleanList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a boolean."""
return super().safe_insert(index, _coerce_to_bool(value), in_place=in_place)

Expand Down
34 changes: 17 additions & 17 deletions src/biocutils/Factor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import warnings
from collections.abc import Sequence
from copy import copy, deepcopy
from typing import Optional, Sequence, Union

import numpy

Expand Down Expand Up @@ -78,7 +78,7 @@ def __iter__(self) -> FactorIterator:
"""
return self

def __next__(self) -> Union[str, None]:
def __next__(self) -> str | None:
"""
Returns:
Level corresponding to the code at the current position, or None
Expand All @@ -102,10 +102,10 @@ class Factor:

def __init__(
self,
codes: Union[numpy.ndarray, Sequence[int]],
levels: Union[StringList, Sequence[str]],
codes: numpy.ndarray | Sequence[int],
levels: StringList | Sequence[str],
ordered: bool = False,
names: Optional[Union[Names, Sequence[str]]] = None,
names: Names | Sequence[str] | None = None,
_validate: bool = True,
):
"""Initialize a Factor object.
Expand Down Expand Up @@ -246,7 +246,7 @@ def names(self) -> Names:
"""Alias for :py:meth:`~get_names`."""
return self.get_names()

def set_names(self, names: Optional[Names], in_place: bool = False) -> "NamedList":
def set_names(self, names: Names | None, in_place: bool = False) -> NamedList:
"""
Args:
names:
Expand Down Expand Up @@ -341,7 +341,7 @@ def __eq__(self, other: Factor):
#####>>>> Slicing <<<<#####
###########################

def get_value(self, index: Union[str, int]) -> Union[str, None]:
def get_value(self, index: str | int) -> str | None:
"""
Args:
index:
Expand Down Expand Up @@ -380,7 +380,7 @@ def get_slice(self, index: SubscriptTypes) -> Factor:
output._names = subset_sequence(self._names, index)
return output

def __getitem__(self, index: SubscriptTypes) -> Union[str, Factor]:
def __getitem__(self, index: SubscriptTypes) -> str | Factor:
"""
If ``index`` is a scalar, this is an alias for :py:meth:`~get_value`.

Expand All @@ -392,7 +392,7 @@ def __getitem__(self, index: SubscriptTypes) -> Union[str, Factor]:
else:
return self.get_slice(NormalizedSubscript(index))

def set_value(self, index: Union[str, int], value: Union[str, None], in_place: bool = False) -> Factor:
def set_value(self, index: str | int, value: str | None, in_place: bool = False) -> Factor:
"""
Args:
index:
Expand Down Expand Up @@ -482,7 +482,7 @@ def set_slice(self, index: SubscriptTypes, value: Factor, in_place: bool = False

return output

def __setitem__(self, index: SubscriptTypes, value: Union[str, Factor]):
def __setitem__(self, index: SubscriptTypes, value: str | Factor):
"""
If ``index`` is a scalar, this is an alias for :py:meth:`~set_value`.

Expand Down Expand Up @@ -588,7 +588,7 @@ def replace_levels(
output._levels = new_levels
return output

def set_levels(self, levels: Union[str, Sequence[str]], remap: bool = True, in_place: bool = False) -> Factor:
def set_levels(self, levels: str | Sequence[str], remap: bool = True, in_place: bool = False) -> Factor:
"""
Alias for :py:meth:`~remap_levels` if ``remap = True``, otherwise an
alias for :py:meth:`~replace_levels`. The first alias is deprecated and
Expand All @@ -600,7 +600,7 @@ def set_levels(self, levels: Union[str, Sequence[str]], remap: bool = True, in_p
else:
return self.replace_levels(levels, in_place=in_place)

def remap_levels(self, levels: Union[str, Sequence[str]], in_place: bool = False) -> Factor:
def remap_levels(self, levels: str | Sequence[str], in_place: bool = False) -> Factor:
"""Remap codes to a replacement list of levels. Each entry of the
remapped ``Factor`` will refer to the same string across the old and
new levels, provided that string is present in both sets of levels.
Expand Down Expand Up @@ -723,10 +723,10 @@ def to_pandas(self):
@staticmethod
def from_sequence(
x: Sequence[str],
levels: Optional[Sequence[str]] = None,
levels: Sequence[str] | None = None,
sort_levels: bool = True,
ordered: bool = False,
names: Optional[Sequence[str]] = None,
names: Sequence[str] | None = None,
**kwargs,
) -> Factor:
"""Convert a sequence of hashable values into a factor.
Expand Down Expand Up @@ -776,7 +776,7 @@ def as_list(self) -> list:
"""
return [self._levels[c] if c >= 0 else None for c in self._codes]

def safe_delete(self, index: Union[int, str, slice], in_place: bool = False) -> Factor:
def safe_delete(self, index: int | str | slice, in_place: bool = False) -> Factor:
"""
Args:
index:
Expand Down Expand Up @@ -810,11 +810,11 @@ def safe_delete(self, index: Union[int, str, slice], in_place: bool = False) ->

return output

def delete(self, index: Union[int, str, slice]):
def delete(self, index: int | str | slice):
"""Alias for :py:meth:`~safe_delete` with ``in_place = True``."""
self.safe_delete(index, in_place=True)

def __delitem__(self, index: Union[int, str, slice]):
def __delitem__(self, index: int | str | slice):
"""Alias for :py:meth:`~delete`."""
self.delete(index)

Expand Down
13 changes: 7 additions & 6 deletions src/biocutils/FloatList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Iterable, Optional, Sequence, Union
from collections.abc import Iterable, Sequence
from typing import Any

from .NamedList import NamedList
from .Names import Names
Expand All @@ -27,7 +28,7 @@ def __init__(self, data: Sequence) -> None:
"""
self._data = data

def __getitem__(self, index: int) -> Optional[float]:
def __getitem__(self, index: int) -> float | None:
"""Get an item and coerce it to float.

Args:
Expand All @@ -49,8 +50,8 @@ class FloatList(NamedList):

def __init__(
self,
data: Optional[Sequence] = None,
names: Optional[Names] = None,
data: Sequence | None = None,
names: Names | None = None,
_validate: bool = True,
):
"""
Expand Down Expand Up @@ -79,15 +80,15 @@ def __init__(

super().__init__(data, names, _validate=_validate)

def set_value(self, index: Union[int, str], value: Any, in_place: bool = False) -> FloatList:
def set_value(self, index: int | str, value: Any, in_place: bool = False) -> FloatList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a float."""
return super().set_value(index, _coerce_to_float(value), in_place=in_place)

def set_slice(self, index: SubscriptTypes, value: Sequence, in_place: bool = False) -> FloatList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to floats."""
return super().set_slice(index, _SubscriptCoercer(value), in_place=in_place)

def safe_insert(self, index: Union[int, str], value: Any, in_place: bool = False) -> FloatList:
def safe_insert(self, index: int | str, value: Any, in_place: bool = False) -> FloatList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a float."""
return super().safe_insert(index, _coerce_to_float(value), in_place=in_place)

Expand Down
13 changes: 7 additions & 6 deletions src/biocutils/IntegerList.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Iterable, Optional, Sequence, Union
from collections.abc import Iterable, Sequence
from typing import Any

from .NamedList import NamedList
from .Names import Names
Expand Down Expand Up @@ -28,7 +29,7 @@ def __init__(self, data: Sequence) -> None:
"""
self._data = data

def __getitem__(self, index: int) -> Optional[int]:
def __getitem__(self, index: int) -> int | None:
"""Get an item and coerce it to integer.

Args:
Expand All @@ -51,8 +52,8 @@ class IntegerList(NamedList):

def __init__(
self,
data: Optional[Sequence] = None,
names: Optional[Names] = None,
data: Sequence | None = None,
names: Names | None = None,
_validate: bool = True,
):
"""
Expand Down Expand Up @@ -80,15 +81,15 @@ def __init__(
data = list(_coerce_to_int(item) for item in original)
super().__init__(data, names, _validate=_validate)

def set_value(self, index: Union[int, str], value: Any, in_place: bool = False) -> IntegerList:
def set_value(self, index: int | str, value: Any, in_place: bool = False) -> IntegerList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a integer."""
return super().set_value(index, _coerce_to_int(value), in_place=in_place)

def set_slice(self, index: SubscriptTypes, value: Sequence, in_place: bool = False) -> IntegerList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to integers."""
return super().set_slice(index, _SubscriptCoercer(value), in_place=in_place)

def safe_insert(self, index: Union[int, str], value: Any, in_place: bool = False) -> IntegerList:
def safe_insert(self, index: int | str, value: Any, in_place: bool = False) -> IntegerList:
"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a integer."""
return super().safe_insert(index, _coerce_to_int(value), in_place=in_place)

Expand Down
Loading
Loading