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

TypeError: Expected list, got numpy.ndarray #4

Closed
vincent6liu opened this issue Aug 26, 2020 · 5 comments
Closed

TypeError: Expected list, got numpy.ndarray #4

vincent6liu opened this issue Aug 26, 2020 · 5 comments
Labels

Comments

@vincent6liu
Copy link

vincent6liu commented Aug 26, 2020

Numpy version is 1.18.5. Running phenograph.cluster(pca_df), where pca_df is either a np.ndarray or pd.DataFrame, gives the following error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-127-8f4599a5b0ca> in <module>
      2 
      3 # Cluster and cluster centrolds
----> 4 communities, graph, Q = phenograph.cluster(pca_df.values)
      5 communities = pd.Series(communities, index=pca_df.index)

~/software/miniconda3/lib/python3.8/site-packages/phenograph/cluster.py in cluster(data, clustering_algo, k, directed, prune, min_cluster_size, jaccard, primary_metric, n_jobs, q_tol, louvain_time_limit, nn_method, partition_type, resolution_parameter, n_iterations, use_weights, seed, **kargs)
    243     else:
    244         del d
--> 245         graph = neighbor_graph(kernel, kernelargs)
    246         print(
    247             "Jaccard graph constructed in {} seconds".format(time.time() - subtic),

~/software/miniconda3/lib/python3.8/site-packages/phenograph/core.py in neighbor_graph(kernel, kernelargs)
     82     :return graph: n-by-n COO sparse matrix
     83     """
---> 84     i, j, s = kernel(**kernelargs)
     85     n, k = kernelargs["idx"].shape
     86     graph = sp.coo_matrix((s, (i, j)), shape=(n, n))

~/software/miniconda3/lib/python3.8/site-packages/phenograph/core.py in parallel_jaccard_kernel(idx)
    152         graph.data[i] = tup[1]
    153 
--> 154     i, j = graph.nonzero()
    155     s = graph.tocoo().data
    156     return i, j, s[s > 0]

~/software/miniconda3/lib/python3.8/site-packages/scipy/sparse/base.py in nonzero(self)
    774 
    775         # convert to COOrdinate format
--> 776         A = self.tocoo()
    777         nz_mask = A.data != 0
    778         return (A.row[nz_mask], A.col[nz_mask])

~/software/miniconda3/lib/python3.8/site-packages/scipy/sparse/base.py in tocoo(self, copy)
    904         the resultant coo_matrix.
    905         """
--> 906         return self.tocsr(copy=False).tocoo(copy=copy)
    907 
    908     def tolil(self, copy=False):

~/software/miniconda3/lib/python3.8/site-packages/scipy/sparse/lil.py in tocsr(self, copy)
    475         indices = np.empty(nnz, dtype=idx_dtype)
    476         data = np.empty(nnz, dtype=self.dtype)
--> 477         _csparsetools.lil_flatten_to_array(self.rows, indices)
    478         _csparsetools.lil_flatten_to_array(self.data, data)
    479 

_csparsetools.pyx in scipy.sparse._csparsetools.lil_flatten_to_array()

_csparsetools.pyx in scipy.sparse._csparsetools._lil_flatten_to_array_int32()

TypeError: Expected list, got numpy.ndarray
@hisplan
Copy link
Member

hisplan commented Aug 28, 2020

Hi Vincent!

I think your input to phenograph.cluster() is actually fine, but the call to the function graph.nonzero() inside the function neighbor_graph() is causing this issue...

This could be a scipy backward compatibility issue. We will try to fix this issue, but in the meantime please let us know if one of the following works for you.

  1. Set n_jobs=1 to suppress parallel processing. Undesirable, but I suspect the error might have something to do with scatter-gather. Trying to see if this is indeed the case.
  2. Downgrade scipy to version 1.4.1.

Thanks.

@hisplan hisplan added the bug label Aug 28, 2020
@YubinXie
Copy link
Member

YubinXie commented Aug 29, 2020

Actually downgrading to scipy 1.4.1 works.

@hisplan
Copy link
Member

hisplan commented Aug 31, 2020

Cool. We will have this fixed as soon as we can. But in the meantime, please use scipy 1.4.1.

@hisplan hisplan changed the title Incompatibility with python3.8 TypeError: Expected list, got numpy.ndarray Sep 2, 2020
@hisplan
Copy link
Member

hisplan commented Oct 7, 2020

@vincent6liu @YubinXie we have released v1.5.7. It should now work with the latest scipy version. Please give it a try and let me know. Thanks.

@hisplan
Copy link
Member

hisplan commented Oct 20, 2020

I'm closing this. Please reopen if you still have an issue.

@hisplan hisplan closed this as completed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants