Skip to content

Commit

Permalink
Merge pull request #11 from mvinyard/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
mvinyard authored May 8, 2023
2 parents 5dc9243 + 5b06332 commit 4b04328
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
__email__ = ", ".join(["[email protected]"])


# -- specify package version: --------------------------------------------------
__version__ = "0.0.21"


# -- import packages: ----------------------------------------------------------
import setuptools
import re
Expand All @@ -19,7 +15,7 @@
# -- run setup: ----------------------------------------------------------------
setuptools.setup(
name="torch-adata",
version="0.0.21",
version="0.0.22rc0",
python_requires=">3.9.0",
author="Michael E. Vinyard",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion torch_adata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


# -- specify package version: --------------------------------------------------
__version__ = "0.0.21"
__version__ = "0.0.22rc0"


# -- import modules: -----------------------------------------------------------
Expand Down
22 changes: 21 additions & 1 deletion torch_adata/_core/_core_ancilliary/_data_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy
import pandas
import torch
import scipy


# -- data type handlers: -----------------------------------------------------------------
Expand Down Expand Up @@ -46,6 +47,23 @@ def is_pandas_categorical(x_arr) -> bool:
return x_arr.__class__ is pandas.Categorical


def is_scipy_sparse(x_arr):
"""
Inspects and indicates if input is a subclass of: scipy.sparse.spmatrix, the base class for all scipy sparse matrices.
Parameters:
-----------
x_arr
type: unknown
Returns:
--------
indicator
type: bool
"""
return isinstance(x_arr, scipy.sparse.spmatrix)


def to_np_array(x_arr) -> numpy.ndarray:
"""
Inspects input. If input is not, numpy.ndarray, it is transformed to numpy.ndarray.
Expand All @@ -62,6 +80,8 @@ def to_np_array(x_arr) -> numpy.ndarray:
"""
if is_numpy_array(x_arr):
return x_arr
if is_scipy_sparse(x_arr):
return x_arr.toarray()
if is_pandas_categorical(x_arr):
return x_arr.to_numpy()
return x_arr.toarray()
Expand Down Expand Up @@ -89,4 +109,4 @@ def as_list(item):
if not isinstance(item, list):
return [item]
return item
return []
return []

0 comments on commit 4b04328

Please sign in to comment.