Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for scipy 1.14 #646

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading