Skip to content

Commit

Permalink
Replaced .A with .toarray() for sparse matrices due to scipy 1.14 upd…
Browse files Browse the repository at this point in the history
…ate (#646)
  • Loading branch information
andr-kun authored Aug 22, 2024
1 parent c4233dd commit 7a83a8b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pertpy/preprocessing/_guide_rna.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def assign_by_threshold(
"""
counts = adata.X if layer is None else adata.layers[layer]
if scipy.sparse.issparse(counts):
counts = counts.A
counts = counts.toarray()

assigned_grnas = np.where(counts >= assignment_threshold, 1, 0)
assigned_grnas = scipy.sparse.csr_matrix(assigned_grnas)
Expand Down Expand Up @@ -92,7 +92,7 @@ def assign_to_max_guide(
"""
counts = adata.X if layer is None else adata.layers[layer]
if scipy.sparse.issparse(counts):
counts = counts.A
counts = counts.toarray()

assigned_grna = np.where(
counts.max(axis=1).squeeze() >= assignment_threshold,
Expand Down Expand Up @@ -152,9 +152,9 @@ def plot_heatmap(

if order_by is None:
if scipy.sparse.issparse(data):
max_values = data.max(axis=1).A.squeeze()
max_values = data.max(axis=1).toarray().squeeze()
data_argmax = data.argmax(axis=1).A.squeeze()
max_guide_index = np.where(max_values != data.min(axis=1).A.squeeze(), data_argmax, -1)
max_guide_index = np.where(max_values != data.min(axis=1).toarray().squeeze(), data_argmax, -1)
else:
max_guide_index = np.where(
data.max(axis=1).squeeze() != data.min(axis=1).squeeze(), data.argmax(axis=1).squeeze(), -1
Expand Down
2 changes: 1 addition & 1 deletion pertpy/tools/_milo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ def plot_nhood_counts_by_cond(
if subset_nhoods is None:
subset_nhoods = nhood_adata.obs_names

pl_df = pd.DataFrame(nhood_adata[subset_nhoods].X.A, columns=nhood_adata.var_names).melt(
pl_df = pd.DataFrame(nhood_adata[subset_nhoods].X.toarray(), columns=nhood_adata.var_names).melt(
var_name=nhood_adata.uns["sample_col"], value_name="n_cells"
)
pl_df = pd.merge(pl_df, nhood_adata.var)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def __len__(self):

def __getitem__(self, idx):
"""Returns a sample and corresponding perturbations applied (labels)"""
sample = self.data[idx].A.squeeze() if scipy.sparse.issparse(self.data) else self.data[idx]
sample = self.data[idx].toarray().squeeze() if scipy.sparse.issparse(self.data) else self.data[idx]
num_label = self.labels.iloc[idx]
str_label = self.pert_labels.iloc[idx]

Expand Down

0 comments on commit 7a83a8b

Please sign in to comment.