scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.9k stars 597 forks source link

TypeError: Can't implicitly convert non-string objects to strings #2321

Open Mari123i opened 2 years ago

Mari123i commented 2 years ago

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Minimal code sample (that we can copy&paste without having any data)

combined_data.var["highly_variable_intersection-0"] = combined_data.var["highly_variable_intersection-0"].astype(str) 

combined_data.write(f"{workspace}Data/Models/Healthy/combined_hvgs_recalculated.h5ad")
TypeError: Can't implicitly convert non-string objects to strings

Above error raised while writing key 'highly_variable_intersection-0' of <class 'h5py._hl.group.Group'> to /

anndata == 0.8.0 scanpy == 1.9.1

I tried converting the columns into various datatypes like str, bool, object, category but that did not help. What is stranger is, that I even deleted this column ( both via del and drop). It solved the issue for another user but for me the same error persists, even after confirming that the column is indeed deleted.

[Paste the output of scanpy.logging.print_versions() leaving a blank line after the details tag]


anndata 0.8.0 scanpy 1.9.1

PIL 9.2.0 absl NA asttokens NA attr 21.4.0 backcall 0.2.0 beta_ufunc NA binom_ufunc NA certifi 2022.06.15 cffi 1.15.1 charset_normalizer 2.1.0 chex 0.1.3 colorama 0.4.5 cycler 0.10.0 cython_runtime NA dateutil 2.8.2 debugpy 1.6.0 decorator 5.1.1 defusedxml 0.7.1 deprecate 0.3.2 docrep 0.3.2 entrypoints 0.4 etils 0.6.0 executing 0.8.3 flatbuffers 2.0 flax 0.5.2 fsspec 2022.5.0 google NA h5py 3.7.0 hypergeom_ufunc NA idna 3.3 igraph 0.9.11 iniconfig NA ipykernel 6.15.1 ipython_genutils 0.2.0 ipywidgets 7.7.1 jax 0.3.14 jaxlib 0.3.14 jedi 0.18.1 joblib 1.1.0 kiwisolver 1.4.3 leidenalg 0.8.10 llvmlite 0.38.1 louvain 0.7.1 matplotlib 3.5.2 matplotlib_inline NA mpl_toolkits NA msgpack 1.0.4 mudata 0.2.0 multipledispatch 0.6.0 natsort 8.1.0 nbinom_ufunc NA newick 1.0.0 numba 0.55.2 numpy 1.22.4 numpyro 0.10.0 opt_einsum v3.3.0 optax 0.1.3 packaging 21.3 pandas 1.4.3 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA pluggy 1.0.0 prompt_toolkit 3.0.30 psutil 5.9.1 ptyprocess 0.7.0 pure_eval 0.2.2 py 1.11.0 pycparser 2.21 pydev_ipython NA pydevconsole NA pydevd 2.8.0 pydevd_file_utils NA pydevd_plugins NA pydevd_tracing NA pygments 2.12.0 pyparsing 3.0.9 pyro 1.8.1 pytest 7.1.2 pytorch_lightning 1.6.5 pytz 2022.1 requests 2.28.1 rich NA scHPL NA scarches 0.5.3 scipy 1.8.1 scvi 0.17.1 seaborn 0.11.2 session_info 1.0.0 setuptools 63.1.0 six 1.16.0 sklearn 1.1.1 socks 1.7.1 stack_data 0.3.0 statsmodels 0.13.2 tensorboard 2.9.1 texttable 1.6.4 threadpoolctl 3.1.0 toolz 0.12.0 torch 1.12.0+cu102 torchmetrics 0.9.2 tornado 6.2 tqdm 4.64.0 traitlets 5.3.0 tree 0.1.7 typing_extensions NA urllib3 1.26.10 wcwidth 0.2.5 wrapt 1.14.1 yaml 6.0 zmq 23.2.0

IPython 8.4.0 jupyter_client 7.3.4 jupyter_core 4.10.0 notebook 6.4.12

Python 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:04:59) [GCC 10.3.0] Linux-3.10.0-1160.71.1.el7.x86_64-x86_64-with-glibc2.17

Session information updated at 2022-09-09 14:21 combined_data.write(f"{workspace}Data/Models/Healthy/combined_hvgs_recalculated.h5ad") combined_data.write(f"{workspace}Data/Models/H

a-munoz-rojas commented 2 years ago

I have also seen this issue. It occurs when trying to save an object after filtering the rank_genes_groups results. I usually have to remove the filtered results for the anndata object to save properly.

LisaSikkema commented 2 years ago

This happens after using anndata.concat if I remember correctly @Mari123i ? Then better to check out the anndata GitHub and submit your issue there

chrissymkcn commented 1 year ago

@a-munoz-rojas that's solution for me! not sure what's the issue with the filtering step