Skip to content

Commit

Permalink
Use SubscriptTypes to describe the subscript types everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 14, 2023
1 parent fe03a7b commit 7d9a46a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/biocutils/Factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .StringList import StringList
from .match import match
from .factorize import factorize
from .normalize_subscript import normalize_subscript
from .normalize_subscript import normalize_subscript, SubscriptTypes
from .is_missing_scalar import is_missing_scalar
from .print_truncated import print_truncated_list
from .combine_sequences import combine_sequences
Expand Down Expand Up @@ -144,7 +144,7 @@ def __str__(self) -> str:
message += "ordered: " + str(self._ordered)
return message

def __getitem__(self, sub: Union[int, bool, Sequence]) -> Union[str, "Factor"]:
def __getitem__(self, sub: SubscriptTypes) -> Union[str, "Factor"]:
"""Subset the ``Factor`` to the specified subset of indices.
Args:
Expand All @@ -170,7 +170,7 @@ def __getitem__(self, sub: Union[int, bool, Sequence]) -> Union[str, "Factor"]:
return None
return type(self)(self._codes[sub], self._levels, self._ordered, validate=False)

def replace(self, sub: Sequence, value: Union[str, "Factor"], in_place: bool = False):
def replace(self, sub: SubscriptTypes, value: Union[str, "Factor"], in_place: bool = False):
"""
Replace items in the ``Factor`` list. The ``subs`` elements in the
current object are replaced with the corresponding values in ``value``.
Expand Down
10 changes: 5 additions & 5 deletions src/biocutils/NamedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from copy import deepcopy

from .Names import Names
from .normalize_subscript import normalize_subscript
from .normalize_subscript import normalize_subscript, SubscriptTypes
from .subset_sequence import subset_sequence
from .combine_sequences import combine_sequences
from .assign_sequence import assign_sequence
Expand Down Expand Up @@ -183,7 +183,7 @@ def get_value(self, index: Union[str, int]) -> Any:
index = _name_to_position(self._names, index)
return self._data[index]

def get_slice(self, index: Union[str, int, bool, Sequence]) -> "NamedList":
def get_slice(self, index: SubscriptTypes) -> "NamedList":
"""
Args:
index:
Expand All @@ -203,7 +203,7 @@ def get_slice(self, index: Union[str, int, bool, Sequence]) -> "NamedList":
outnames = subset_sequence(self._names, index)
return type(self)(outdata, outnames, _validate=False)

def __getitem__(self, index: Union[str, int, bool, Sequence]) -> Union["NamedList", Any]:
def __getitem__(self, index: SubscriptTypes) -> Union["NamedList", Any]:
"""
If ``index`` is a scalar, this is an alias for :py:attr:`~get_item`.
Expand Down Expand Up @@ -262,7 +262,7 @@ def set_value(self, index: Union[str, int], value: Any, in_place: bool = False)

return output

def set_slice(self, index: Union[int, str, slice], value: Sequence, in_place: bool = False) -> "NamedList":
def set_slice(self, index: SubscriptTypes, value: Sequence, in_place: bool = False) -> "NamedList":
"""
Args:
index:
Expand Down Expand Up @@ -303,7 +303,7 @@ def set_slice(self, index: Union[int, str, slice], value: Sequence, in_place: bo
output._data[j] = value[i]
return output

def __setitem__(self, index: Union[int, str, slice], value: Any):
def __setitem__(self, index: SubscriptTypes, value: Any):
"""
If ``index`` is a scalar, this is an alias for :py:attr:`~set_item`
with ``in_place = True``.
Expand Down
6 changes: 2 additions & 4 deletions src/biocutils/StringList.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

from .Names import Names
from .NamedList import NamedList
from .subset_sequence import subset_sequence
from .combine_sequences import combine_sequences
from .assign_sequence import assign_sequence
from .normalize_subscript import SubscriptTypes


def _coerce_to_str(x: Any) -> bool:
Expand Down Expand Up @@ -57,7 +55,7 @@ def set_value(self, index: Union[int, str], value: Any, in_place: bool = False)
"""Calls :py:meth:`~NamedList.NamedList.set_value` after coercing ``value`` to a string."""
return super().set_value(index, _coerce_to_str(value), in_place=in_place)

def set_slice(self, index: Union[int, str, slice], value: Sequence, in_place: bool = False) -> "StringList":
def set_slice(self, index: SubscriptTypes, value: Sequence, in_place: bool = False) -> "StringList":
"""Calls :py:meth:`~NamedList.NamedList.set_slice` after coercing ``value`` to strings."""
return super().set_slice(index, _SubscriptCoercer(value), in_place=in_place)

Expand Down

0 comments on commit 7d9a46a

Please sign in to comment.