Skip to content

spc.est_spectra returns error "AttributeError: 'Series' object has no attribute 'nonzero'" #52

@halterc

Description

@halterc

Hi

when I try to run the example from the tutorial locally (the online colab crashes due to running out of memory), I get the following error when I try to run:

model = spc.est_spectra(adata=adata, gene_set_dictionary=annotations, use_highly_variable=True, cell_type_key="cell_type_annotations", use_weights=True, lam=0.1, # varies depending on data and gene sets, try between 0.5 and 0.001 delta=0.001, kappa=None, rho=0.001, use_cell_types=True, n_top_vals=50, label_factors=True, overlap_threshold=0.2, clean_gs = True, min_gs_num = 3, num_epochs=2 #here running only 2 epochs for time reasons, we recommend 10,000 epochs for most datasets )


AttributeError Traceback (most recent call last)
/var/folders/tw/3_vqzv_517515r5vv8pnrljc0000gn/T/ipykernel_10048/2900975804.py in ?()
----> 1 model = spc.est_spectra(adata=bdata,
2 gene_set_dictionary=bnnotations,
3 use_highly_variable=True,
4 cell_type_key="cell_type_annotations",

/opt/homebrew/anaconda3/lib/python3.11/site-packages/Spectra/Spectra.py in ?(adata, gene_set_dictionary, L, use_highly_variable, cell_type_key, use_weights, lam, delta, kappa, rho, use_cell_types, n_top_vals, filter_sets, label_factors, clean_gs, min_gs_num, overlap_threshold, **kwargs)
1534 if use_highly_variable:
1535 idx_to_use = (
1536 bools | adata.var.highly_variable
1537 ) # take union of highly variable and gene set genes (todo: add option to change this at some point)
-> 1538 X = adata.X[:, idx_to_use]
1539 vocab = adata.var_names[idx_to_use]
1540 adata.var["spectra_vocab"] = idx_to_use
1541 else:

/opt/homebrew/anaconda3/lib/python3.11/site-packages/scipy/sparse/_index.py in ?(self, key)
29 def getitem(self, key):
---> 30 index, new_shape = self._validate_indices(key)
31
32 # 1D array
33 if len(index) == 1:

/opt/homebrew/anaconda3/lib/python3.11/site-packages/scipy/sparse/_index.py in ?(self, key)
265 if ix.shape != mid_shape:
266 raise IndexError(
267 f"bool index {i} has shape {mid_shape} instead of {ix.shape}"
268 )
--> 269 index.extend(ix.nonzero())
270 array_indices.extend(range(index_ndim, tmp_ndim))
271 index_ndim = tmp_ndim
272 else: # dense array

/opt/homebrew/anaconda3/lib/python3.11/site-packages/pandas/core/generic.py in ?(self, name)
6295 and name not in self._accessors
6296 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6297 ):
6298 return self[name]
-> 6299 return object.getattribute(self, name)

AttributeError: 'Series' object has no attribute 'nonzero'

Seems adata.var is always a pandas dataframe, as this returns an error
adata.var = adata.var.to_numpy()

Am I missing something?

Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions