Skip to content

Commit

Permalink
preferred fix for dealing with backed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ivirshup committed Apr 10, 2024
1 parent a3671bf commit d5f0005
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/anndata/_core/sparse_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,9 @@ class backed_csc_matrix(backed_csc, ss.csc_matrix):
"""backed_csc_matrix"""


class backed_csr_array(backed_csr, ss.csr_array):
"""backed_csr_array"""


class backed_csc_array(backed_csc, ss.csc_array):
"""backed_csc_array"""


FORMATS = [
BackedFormat("csr", backed_csr_matrix, ss.csr_matrix),
BackedFormat("csc", backed_csc_matrix, ss.csc_matrix),
BackedFormat("csr", backed_csr_array, ss.csr_array),
BackedFormat("csc", backed_csc_array, ss.csc_array),
]


Expand Down Expand Up @@ -320,13 +310,6 @@ def mean_slice_length(slices):
return [], [], [0]


def get_format(data: ss.spmatrix) -> str:
for fmt, _, memory_class in FORMATS:
if isinstance(data, memory_class):
return fmt
raise ValueError(f"Data type {type(data)} is not supported.")


def get_memory_class(format: str, use_sparray_in_io=False) -> type[ss.spmatrix]:
for fmt, _, memory_class in FORMATS:
if format == fmt:
Expand Down Expand Up @@ -511,10 +494,10 @@ def append(self, sparse_matrix: ss.spmatrix | SpArray):
raise NotImplementedError(
f"The append method for format {self.format} " f"is not implemented."
)
if self.format != get_format(sparse_matrix):
if self.format != sparse_matrix.format:
raise ValueError(
f"Matrices must have same format. Currently are "
f"{self.format!r} and {get_format(sparse_matrix)!r}"
f"{self.format!r} and {sparse_matrix.format!r}"
)
indptr_offset = len(self.group["indices"])
if self.group["indptr"].dtype == np.int32:
Expand Down

0 comments on commit d5f0005

Please sign in to comment.