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

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part. #1109

Closed
GaF123 opened this issue Aug 7, 2023 · 9 comments
Labels
duplicate Duplicated issue

Comments

@GaF123
Copy link

GaF123 commented Aug 7, 2023

Thank you so much for your great tool!

I use seuratdisk convert rds to h5ad, and use velocyto convert bam to loom. And I merged these 2 files. and when I got to the: scv.tl.velocity_graph(adata)
It shows: ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part.

Here is my all codes:
import anndata
import scvelo as scv
import pandas as pd
import numpy as np
import scanpy as sc
import matplotlib as plt
file_path = '/Users/eaiscui/Desktop/temp/mouseforvelocyto_final.h5ad'
adata=sc.read_h5ad('mouseforvelocyto_final.h5ad')
adata.obs.seurat_clusters=adata.obs.seurat_clusters.astype('category')
ldata1 = anndata.read_loom('/Users/eaiscui/Desktop/loomfiles/Dminus_H2B.loom')
ldata2 = anndata.read_loom('/Users/eaiscui/Desktop/loomfiles/Dplus_H2B.loom')

rename barcodes in order to merge:

barcodes = [bc.split(':')[1] for bc in ldata1.obs.index.tolist()]
barcodes = [bc[0:len(bc)-1] + '_10' for bc in barcodes]
ldata1.obs.index = barcodes
barcodes = [bc.split(':')[1] for bc in ldata2.obs.index.tolist()]
barcodes = [bc[0:len(bc)-1] + '_11' for bc in barcodes]
ldata2.obs.index = barcodes

make variable names unique

ldata1.var_names_make_unique()
ldata2.var_names_make_unique()

concatenate the three loom

ldata = ldata1.concatenate([ldata2])
scv.utils.clean_obs_names(adata)
scv.utils.clean_obs_names(ldata)
adata = scv.utils.merge(adata, ldata)
scv.settings.verbosity = 3 # show errors(0), warnings(1), info(2), hints(3)
scv.settings.presenter_view = True # set max width size for presenter view
scv.set_figure_params('scvelo') # for beautified visualization
scv.pl.proportions(adata)
scv.pp.filter_genes(adata, min_shared_counts=20)
scv.pp.normalize_per_cell(adata)
scv.pp.filter_genes_dispersion(adata, n_top_genes=2000)
scv.pp.log1p(adata)
scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000)
scv.pp.moments(adata, n_pcs=30, n_neighbors=30)
scv.tl.velocity(adata)
scv.tl.velocity_graph(adata)

Then it shows:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 4) + inhomogeneous part.

Please help! Thank you so much!

@jeffhsu3
Copy link

jeffhsu3 commented Aug 8, 2023

Similar issue but with alevin-fry data, concatenated with scanpy.

adatas = []
for sample in samples:
    adata = pyroe.load_fry(
        f"alevin_fry/{sample}/", 
        output_format="snRNA")
    adata.obs['sample'] = sample
    adatas.append(adata)

adata = sc.concat(adatas, index_unique='_')

@maartenciers
Copy link

It has to do with the numpy version they used. It works when you lower numpy to 1.21.1 but installing this is not possible in more recent python versions, so I switched my conda env to python 3.8 and then I could downgrade. It would be nice if they fixed this issue for more recent python/numpy versions.

@jeffhsu3
Copy link

jeffhsu3 commented Aug 8, 2023

Guessing this is the change in numpy: numpy/numpy#14794 . Would a try except at the np.array(res) be an accepted way to deal with handling versions of numpy?

@GaF123
Copy link
Author

GaF123 commented Aug 9, 2023

Thank you for your advice, it works for me!

@WeilerP
Copy link
Member

WeilerP commented Aug 9, 2023

The issue has been reported before and has been fixed in #1059.

@WeilerP WeilerP closed this as completed Aug 9, 2023
@WeilerP WeilerP added the duplicate Duplicated issue label Aug 9, 2023
@yamihn
Copy link

yamihn commented Sep 24, 2023

hi @WeilerP how did you solve the issue?

@ramadatta
Copy link
Member

I used the following commands and created a new environment based on this #1040 (comment).

conda create -n scvelo_env python=3.9
conda activate scvelo_env
conda install numpy scipy cython numba matplotlib scikit-learn h5py click
pip install notebook
pip install scanpy
pip install leidenalg
pip install scvelo
pip install pandas==1.1.5 
pip install numpy==1.21.1

This error is resolved for me.

@brendamelano
Copy link

Hello, I have tried the tips above and in different threads including setting different environments with python=3.8 or 3.6. I have downgraded pandas and numpy with either numba compatability issues or kernels dying when generating umaps. Is there a way to fix this inhomogenous shape issue without downgrading libraries that the developers are working on?

@hernandezvargash
Copy link

Hi, same issue here.
I tried the downgrading solution, as explained here. I'm also working on a fresh install of Ubuntu 22.04. Only difference is I'm using mamba instead of conda.
Then I got a matplotlib error, so also downgraded to version 3.5.1 as suggested in this thread.
This took me back to the original "inhomogeneous" error.
So, I definitely agree with @brendamelano , we need a more stable solution with updated libraries.
Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Duplicated issue
Projects
None yet
Development

No branches or pull requests

8 participants