Skip to content

Commit

Permalink
simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Oct 17, 2023
1 parent 3145f62 commit 1663d3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/summarizedexperiment/utils/combiners.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import Dict, List, Literal, Tuple
from typing import Any, Dict, List, Literal, Tuple

from biocframe import BiocFrame
from biocgenerics import rownames
from numpy import argwhere, find_common_type, ndarray
from pandas import DataFrame, Index, concat
from scipy.sparse import lil_matrix

from ..types import ArrayTypes, BiocOrPandasFrame
from .validators import validate_names, validate_shapes

# from ..SummarizedExperiment import SummarizedExperiment
Expand All @@ -16,17 +15,17 @@
__license__ = "MIT"


def impose_common_precision(*x: ArrayTypes) -> List[ArrayTypes]:
def impose_common_precision(*x: Any) -> List[Any]:
"""Check and transform input arrays into common dtypes.
Args:
*x (ArrayTypes): Array like objects.
*x (Any): Array like objects.
``x`` may be either a :py:class:`~scipy.sparse.lil_matrix` or
a :py:class:`~numpy.ndarray`.
Returns:
List[ArrayTypes]: All transformed matrices.
List[Any]: All transformed matrices.
"""
common_dtype = find_common_type([m.dtype for m in x], [])
return [(m.astype(common_dtype) if m.dtype != common_dtype else m) for m in x]
Expand Down Expand Up @@ -62,15 +61,15 @@ def combine_metadata(experiments: List["SummarizedExperiment"]) -> Dict:


def combine_frames(
x: List[BiocOrPandasFrame],
x: List[BiocFrame],
use_names: bool,
axis: int,
remove_duplicate_columns: bool,
) -> DataFrame:
"""Combine a series of `DataFrame`-like objects.
Args:
x (List[BiocOrPandasFrame]): Input frames.
x (List[BiocFrame]): Input frames.
May be either a :py:class:`~biocframe.BiocFrame.BiocFrame` or
:py:class:`~pandas.DataFrame`.
Expand Down
14 changes: 7 additions & 7 deletions src/summarizedexperiment/utils/validators.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from typing import List

from ..types import BiocOrPandasFrame
from biocframe import BiocFrame

__author__ = "keviny2, jkanche"
__copyright__ = "keviny2"
__license__ = "MIT"


def _validate_single_frame(df: BiocOrPandasFrame) -> bool:
def _validate_single_frame(df: BiocFrame) -> bool:
"""Validate there are no None or duplicated names.
Args:
df (BiocOrPandasFrame): Object to validate.
df (BiocFrame): Object to validate.
``df`` may be a :py;class:`~biocframe.BiocFrame.BiocFrame` object.
Alternatively, ``df`` may be a :py:class:`~pandas.DataFrame`.
Expand All @@ -24,11 +24,11 @@ def _validate_single_frame(df: BiocOrPandasFrame) -> bool:
return (not any_null) and (not any_duplicates)


def validate_names(x: List[BiocOrPandasFrame]) -> bool:
def validate_names(x: List[BiocFrame]) -> bool:
"""Validate names across experiments.
Args:
x (List[BiocOrPandasFrame]): Objects to validate.
x (List[BiocFrame]): Objects to validate.
``x`` may be a :py;class:`~biocframe.BiocFrame.BiocFrame` object.
Alternatively, ``x`` may be a :py:class:`~pandas.DataFrame`.
Expand All @@ -47,11 +47,11 @@ def validate_names(x: List[BiocOrPandasFrame]) -> bool:
return is_valid_names


def validate_shapes(x: List[BiocOrPandasFrame]):
def validate_shapes(x: List[BiocFrame]):
"""Validate shapes across experiments.
Args:
x (List[BiocOrPandasFrame]): Objects to validate.
x (List[BiocFrame]): Objects to validate.
``x`` may be a :py;class:`~biocframe.BiocFrame.BiocFrame` object.
Alternatively, ``x`` may be a :py:class:`~pandas.DataFrame`.
Expand Down

0 comments on commit 1663d3d

Please sign in to comment.