Repository: theislab/cellrank (language: python)

Issue:
scVelo objects not able to .write h5ad file
When trying to save my anndata object as h5ad after processing with scVelo with .write
```
TypeError: No method has been defined for writing <enum 'VelocityMode'> elements to <class 'h5py._hl.group.Group'>

Above error raised while writing key 'mode' of <class 'h5py._hl.group.Group'> to /
```


Discussion / hints:
Thanks for the report. Could you let us know what the versions of packages are in this environment?
<details>
<summary> Version info </summary>

```
Package                           Version              Location    
--------------------------------- -------------------- ------------
absl-py                           1.0.0                
adjustText                        0.7.3                
aiohttp                           3.8.1                
aiosignal                         1.2.0                
airr                              1.3.1                
alabaster                         0.7.12               
amqp                              5.0.9                
aniso8601                         9.0.1                
anndata                           0.7.8                
anndata2ri                        1.0.6                
annoy                             1.17.0               
ansi2html                         1.6.0                
anyio                             3.5.0                
appdirs                           1.4.4                
arboreto                          0.1.6                
argon2-cffi                       21.3.0               
argon2-cffi-bindings              21.2.0               
arrow                             1.2.2                
asciitree                         0.3.3                
asgiref                           3.5.0                
astroid                           2.9.3                
astunparse                        1.6.3                
async-timeout                     4.0.2                
attrs                             21.4.0               
autopep8                          1.6.0                
Babel                             2.9.1                
backcall                          0.2.0                
backports.zoneinfo                0.2.1                
batchglm                          0.7.4                
bbknn                             1.5.1                
beautifulsoup4                    4.10.0               
billiard                          3.6.4.0              
binaryornot                       0.4.4                
biopython                         1.79                 
bioservices                       1.8.3                
black                             22.1.0               
bleach                            4.1.0                
bokeh                             2.4.2                
boltons                           21.0.0               
boto3                             1.20.29              
botocore                          1.23.29              
Brotli                            1.0.9                
bs4                               0.0.1                
cachetools                        4.2.4                
cachey                            0.2.1                
cattrs                            1.10.0               
celery                            5.2.3                
cellrank                          1.5.1                
cellxgene                         1.0.0                
certifi                           2019.11.28           
cffi                              1.15.0               
chardet                           3.0.4                
charset-normalizer                2.0.10               
click                             8.0.3                
click-didyoumean                  0.3.0                
click-plugins                     1.1.1                
click-repl                        0.2.0                
cloudpickle                       2.0.0                
cmake                             3.22.2               
colorama                          0.4.4                
coloredlogs                       15.0.1               
colorlog                          6.6.0                
colormath                         3.0.0                
commonmark                        0.9.1                
ConfigArgParse                    1.5.3                
configparser                      5.2.0                
cookiecutter                      1.7.3                
crossref-commons                  0.0.7                
ctxcore                           0.1.1                
cycler                            0.11.0               
Cython                            0.29.27              
cytoolz                           0.11.2               
dash                              1.20.0               
dash-building-blocks              0.1.2                
dash-core-components              2.0.0                
dash-cytoscape                    0.3.0                
dash-html-components              2.0.0                
dash-renderer                     1.9.1                
dash-table                        4.11.3               
dask                              2021.12.0            
dask-image                        2021.12.0            
dbus-python                       1.2.16               
debugpy                           1.5.1                
decorator                         5.1.0                
defusedxml                        0.7.1                
Deprecated                        1.2.13               
diffxpy                           0.7.4                
dill                              0.3.4                
distributed                       2021.12.0            
distro-info                       0.23ubuntu1          
Django                            3.2.10               
django-celery-beat                2.2.1                
django-celery-results             2.3.0                
django-crispy-forms               1.14.0               
django-extensions                 3.1.5                
django-filter                     21.1                 
django-js-asset                   1.2.2                
django-markdownify                0.9.0                
django-mptt                       0.13.4               
django-multiselectfield           0.1.12               
django-plotly-dash                1.6.6                
django-timezone-field             4.2.3                
django-widget-tweaks              1.4.12               
djangorestframework               3.13.1               
djangorestframework-datatables    0.7.0                
docrep                            0.3.2                
docstring-parser                  0.13                 
docutils                          0.17.1               
dpd-components                    0.1.0                
dunamai                           1.8.0                
easydev                           0.12.0               
entrypoints                       0.3                  
et-xmlfile                        1.1.0                
fa2                               0.3.5                
fastcluster                       1.2.4                
fastcore                          1.3.27               
fasteners                         0.17.3               
fbpca                             1.0                  
flake8                            4.0.1                
flasgger                          0.9.5                
Flask                             2.0.2                
Flask-Compress                    1.10.1               
Flask-Cors                        3.0.10               
Flask-RESTful                     0.3.9                
flask-server-timing               0.1.2                
flask-talisman                    0.8.1                
flatbuffers                       1.12                 
flatten-dict                      0.4.2                
fonttools                         4.28.5               
fpdf                              1.7.2                
freetype-py                       2.2.0                
frozendict                        2.1.3                
frozenlist                        1.2.0                
fsspec                            0.7.4                
future                            0.18.2               
fuzzywuzzy                        0.18.0               
gast                              0.4.0                
GDAL                              3.0.4                
geosketch                         1.2                  
get-version                       3.5.3                
gevent                            21.12.0              
gitdb                             4.0.9                
GitPython                         3.1.26               
google-auth                       2.3.3                
google-auth-oauthlib              0.4.6                
google-pasta                      0.2.0                
gprofiler-official                1.0.0                
graphtools                        1.5.2                
greenlet                          1.1.2                
grequests                         0.6.0                
grpcio                            1.43.0               
gsea-api                          0.3.4                
gseapy                            0.10.7               
gunicorn                          20.1.0               
h5py                              2.10.0               
harmonypy                         0.0.5                
HeapDict                          1.0.1                
hsluv                             5.0.2                
humanfriendly                     10.0                 
idna                              2.8                  
igraph                            0.9.8                
imageio                           2.14.1               
imagesize                         1.3.0                
importlib-metadata                4.10.0               
importlib-resources               5.4.0                
inflect                           5.3.0                
iniconfig                         1.1.1                
interlap                          0.2.7                
intervaltree                      2.1.0                
ipdb                              0.13.9               
ipykernel                         6.6.1                
ipympl                            0.8.5                
ipython                           7.31.0               
ipython-genutils                  0.2.0                
ipywidgets                        7.6.5                
isort                             5.10.1               
iterativeWGCNA                    1.1.6                
itsdangerous                      2.0.1                
jedi                              0.18.1               
Jinja2                            3.0.3                
jinja2-time                       0.2.0                
jmespath                          0.10.0               
joblib                            0.17.0               
json5                             0.9.6                
jsonschema                        4.3.3                
jupyter-client                    7.1.0                
jupyter-core                      4.9.1                
jupyter-dash                      0.4.0                
jupyter-helpers                   0.2.3                
jupyter-lsp                       1.5.1                
jupyter-server                    1.13.4               
jupyter-server-mathjax            0.2.3                
jupyterlab                        3.2.8                
jupyterlab-code-formatter         1.4.10               
jupyterlab-git                    0.34.2               
jupyterlab-lsp                    3.10.0               
jupyterlab-pygments               0.1.2                
jupyterlab-server                 2.10.3               
jupyterlab-templates              0.3.1                
jupyterlab-widgets                1.0.2                
jupytext                          1.13.6               
keras                             2.7.0                
Keras-Preprocessing               1.1.2                
kiwisolver                        1.3.2                
kombu                             5.2.3                
lazy-import                       0.2.2                
lazy-object-proxy                 1.7.1                
lckr-jupyterlab-variableinspector 3.0.9                
leidenalg                         0.8.8                
libclang                          13.0.0               
llvmlite                          0.37.0               
locket                            0.2.1                
loompy                            3.0.6                
louvain                           0.7.1                
lxml                              4.7.1                
lzstring                          1.0.4                
magicgui                          0.3.4                
Markdown                          3.3.6                
markdown-it-py                    1.1.0                
MarkupSafe                        2.0.1                
matplotlib                        3.5.1                
matplotlib-inline                 0.1.3                
mccabe                            0.6.1                
mdit-py-plugins                   0.3.0                
mistune                           0.8.4                
msgpack                           1.0.3                
multidict                         5.2.0                
multiprocessing-on-dill           3.5.0a4              
multiqc                           1.11                 
mypy-extensions                   0.4.3                
napari                            0.4.13               
napari-console                    0.0.4                
napari-plugin-engine              0.2.0                
napari-svg                        0.1.6                
natsort                           8.0.2                
nbclassic                         0.3.5                
nbclient                          0.5.9                
nbconvert                         6.4.0                
nbdime                            3.1.1                
nbformat                          5.1.3                
nbresuse                          0.4.0                
neo4j                             4.4.1                
nest-asyncio                      1.5.4                
networkx                          2.6.3                
notebook                          6.4.6                
npe2                              0.1.2                
numba                             0.54.1               
numcodecs                         0.9.1                
numexpr                           2.8.1                
numpy                             1.20.0               
numpy-groupies                    0.9.14               
numpydoc                          1.2                  
oauthlib                          3.1.1                
obonet                            0.3.0                
omnipath                          1.0.5                
openpyxl                          3.0.9                
opt-einsum                        3.3.0                
Owlready2                         0.36                 
packaging                         21.3                 
pandas                            1.2.5                
pandocfilters                     1.5.0                
parasail                          1.2.4                
parso                             0.8.3                
partd                             1.2.0                
passlib                           1.7.4                
path                              16.2.0               
pathlib                           1.0.1                
pathspec                          0.9.0                
patsy                             0.5.2                
peepdis                           0.1.13               
pexpect                           4.8.0                
phate                             1.0.7                
PhenoGraph                        1.5.7                
pickleshare                       0.7.5                
Pillow                            9.0.0                
PIMS                              0.5                  
Pint                              0.18                 
pip                               20.0.2               
platformdirs                      2.4.1                
plotly                            5.5.0                
pluggy                            1.0.0                
pooch                             1.6.0                
poyo                              0.5.0                
progressbar2                      4.0.0                
prometheus-client                 0.12.0               
prompt-toolkit                    3.0.24               
protobuf                          3.19.1               
psutil                            5.9.0                
psycopg2                          2.9.3                
psygnal                           0.2.0                
ptvsd                             4.3.2                
ptyprocess                        0.7.0                
py                                1.11.0               
pyarrow                           0.16.0               
pyasn1                            0.4.8                
pyasn1-modules                    0.2.8                
pybiomart                         0.2.0                
pycodestyle                       2.8.0                
pycparser                         2.21                 
pydantic                          1.9.0                
pyDeprecate                       0.3.0                
pydocstyle                        6.1.1                
pyflakes                          2.4.0                
pygam                             0.8.0                
Pygments                          2.11.1               
PyGObject                         3.36.0               
pygpcca                           1.0.3                
PyGSP                             0.5.1                
PyHGNC                            0.2.4                
pylint                            2.12.2               
PyMySQL                           1.0.2                
pynndescent                       0.5.5                
PyOpenGL                          3.1.5                
pyparsing                         3.0.6                
PyQt5                             5.15.6               
PyQt5-Qt5                         5.15.2               
PyQt5-sip                         12.9.0               
pyro-api                          0.1.2                
pyro-ppl                          1.8.0                
pyrsistent                        0.18.0               
pysam                             0.18.0               
pyscenic                          0.11.2               
pytest                            6.2.5                
python-apt                        2.0.0+ubuntu0.20.4.6 
python-crontab                    2.6.0                
python-dateutil                   2.8.2                
python-debian                     0.1.36ubuntu1        
python-igraph                     0.9.8                
python-Levenshtein                0.12.2               
python-lsp-jsonrpc                1.0.0                
python-lsp-server                 1.3.3                
python-slugify                    5.0.2                
python-utils                      3.1.0                
pytoml                            0.1.21               
pytomlpp                          1.0.10               
pytorch-lightning                 1.3.1                
pytz                              2021.3               
pytz-deprecation-shim             0.1.0.post0          
PyWavelets                        1.2.0                
PyYAML                            5.4.1                
pyzmq                             22.3.0               
qtconsole                         5.2.2                
QtPy                              2.0.0                
questionary                       1.10.0               
ratelimit                         2.2.1                
requests                          2.24.0               
requests-cache                    0.9.1                
requests-oauthlib                 1.3.0                
requests-unixsocket               0.2.0                
retrying                          1.3.3                
rich                              10.16.2              
rope                              0.22.0               
rpy2                              3.4.2                
rsa                               4.8                  
s-gd2                             1.8                  
s3fs                              0.4.2                
s3transfer                        0.5.0                
scanorama                         1.7.1                
scanpy                            1.8.2                
scikit-image                      0.19.1               
scikit-learn                      1.0.2                
scikit-misc                       0.1.4                
scipy                             1.7.3                
scirpy                            0.10.1               
scprep                            1.1.0                
scrublet                          0.2.3                
scvelo                            0.2.4                
scvi-tools                        0.14.5               
seaborn                           0.11.2               
Send2Trash                        1.8.0                
setuptools                        59.6.0               
setuptools-scm                    6.4.2                
sfaira                            0.3.9                
sidecar                           0.5.1                
simplejson                        3.17.6               
sinfo                             0.3.4                
six                               1.14.0               
slicerator                        1.0.0                
smmap                             5.0.0                
sniffio                           1.2.0                
snowballstemmer                   2.2.0                
solo-sc                           1.2                  /source/solo
sortedcontainers                  2.4.0                
soupsieve                         2.3.1                
sparse                            0.13.0               
spectra                           0.0.11               
Sphinx                            4.4.0                
sphinxcontrib-applehelp           1.0.2                
sphinxcontrib-devhelp             1.0.2                
sphinxcontrib-htmlhelp            2.0.0                
sphinxcontrib-jsmath              1.0.1                
sphinxcontrib-qthelp              1.0.3                
sphinxcontrib-serializinghtml     1.1.5                
SQLAlchemy                        1.4.31               
sqlparse                          0.4.2                
squarify                          0.4.3                
squidpy                           1.1.2                
statsmodels                       0.13.1               
stdlib-list                       0.8.0                
suds-community                    1.0.0                
superqt                           0.2.5.post1          
switchlang                        0.1.0                
tables                            3.7.0                
tasklogger                        1.1.0                
tblib                             1.7.0                
tenacity                          8.0.1                
tensorboard                       2.7.0                
tensorboard-data-server           0.6.1                
tensorboard-plugin-wit            1.8.1                
tensorflow                        2.7.0                
tensorflow-estimator              2.7.0                
tensorflow-io-gcs-filesystem      0.23.1               
termcolor                         1.1.0                
terminado                         0.12.1               
testpath                          0.5.0                
text-unidecode                    1.3                  
texttable                         1.6.4                
threadpoolctl                     3.0.0                
tifffile                          2021.11.2            
toml                              0.10.2               
tomli                             2.0.0                
toolz                             0.11.2               
torch                             1.10.1               
torchmetrics                      0.6.2                
tornado                           6.1                  
tqdm                              4.62.3               
traitlets                         5.1.1                
trimap                            1.0.15               
typeguard                         2.13.3               
typer                             0.4.0                
typing-extensions                 4.0.1                
tzdata                            2021.5               
tzlocal                           4.1                  
ujson                             5.1.0                
umap-learn                        0.5.2                
unattended-upgrades               0.1                  
url-normalize                     1.4.3                
urllib3                           1.25.8               
versioneer                        0.21                 
vine                              5.0.0                
vispy                             0.9.4                
wcwidth                           0.2.5                
webencodings                      0.5.1                
websocket-client                  1.2.3                
Werkzeug                          2.0.2                
wheel                             0.34.2               
widgetsnbextension                3.5.2                
wrapt                             1.13.3               
WTForms                           3.0.1                
xarray                            0.21.0               
xeus-python                       0.13.6               
xeus-python-shell                 0.2.0                
xlrd                              1.2.0                
xmltodict                         0.12.0               
yamlordereddictloader             0.4.0                
yapf                              0.32.0               
yarl                              1.7.2                
zarr                              2.10.3               
zict                              2.0.0                
zipp                              3.7.0                
zope.event                        4.5.0                
zope.interface                    5.4.0  
```


</details>
Great thanks!

Could you share an example of how this object got created? Ideally something I could run on my machine. A full traceback would also be great.

---------------

@WeilerP, anything obvious going on here? Should there be a `VelocityMode` in an `AnnData`?
Traceback:
```
... storing 'subentity__entity__sample__indication' as categorical
... storing 'subentity__entity__sample__tissue' as categorical
Creating converter from 5 to 3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
    213         try:
--> 214             return func(elem, key, val, *args, **kwargs)
    215         except Exception as e:

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in write_elem(f, k, elem, modifiers, *args, **kwargs)
    174     else:
--> 175         _REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
    176 

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in get_writer(self, dest_type, typ, modifiers)
     63         if (dest_type, typ, modifiers) not in self.write:
---> 64             raise TypeError(
     65                 f"No method has been defined for writing {typ} elements to {dest_type}"

TypeError: No method has been defined for writing <enum 'VelocityMode'> elements to <class 'h5py._hl.group.Group'>

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_14002/2448738011.py in <module>
----> 1 _ad.write("/data/test.h5ad")

/usr/local/lib/python3.8/dist-packages/anndata/_core/anndata.py in write_h5ad(self, filename, compression, compression_opts, force_dense, as_dense)
   1916             filename = self.filename
   1917 
-> 1918         _write_h5ad(
   1919             Path(filename),
   1920             self,

/usr/local/lib/python3.8/dist-packages/anndata/_io/h5ad.py in write_h5ad(filepath, adata, force_dense, as_dense, dataset_kwargs, **kwargs)
    103         write_elem(f, "varp", dict(adata.varp), dataset_kwargs=dataset_kwargs)
    104         write_elem(f, "layers", dict(adata.layers), dataset_kwargs=dataset_kwargs)
--> 105         write_elem(f, "uns", dict(adata.uns), dataset_kwargs=dataset_kwargs)
    106 
    107 

/usr/local/lib/python3.8/dist-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
    212     def func_wrapper(elem, key, val, *args, **kwargs):
    213         try:
--> 214             return func(elem, key, val, *args, **kwargs)
    215         except Exception as e:
    216             if "Above error raised while writing key" in format(e):

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in write_elem(f, k, elem, modifiers, *args, **kwargs)
    173         )
    174     else:
--> 175         _REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
    176 
    177 

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in wrapper(g, k, *args, **kwargs)
     22         @wraps(func)
     23         def wrapper(g, k, *args, **kwargs):
---> 24             result = func(g, k, *args, **kwargs)
     25             g[k].attrs.setdefault("encoding-type", spec.encoding_type)
     26             g[k].attrs.setdefault("encoding-version", spec.encoding_version)

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/methods.py in write_mapping(f, k, v, dataset_kwargs)
    279     g = f.create_group(k)
    280     for sub_k, sub_v in v.items():
--> 281         write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)
    282 
    283 

/usr/local/lib/python3.8/dist-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
    212     def func_wrapper(elem, key, val, *args, **kwargs):
    213         try:
--> 214             return func(elem, key, val, *args, **kwargs)
    215         except Exception as e:
    216             if "Above error raised while writing key" in format(e):

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in write_elem(f, k, elem, modifiers, *args, **kwargs)
    173         )
    174     else:
--> 175         _REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
    176 
    177 

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in wrapper(g, k, *args, **kwargs)
     22         @wraps(func)
     23         def wrapper(g, k, *args, **kwargs):
---> 24             result = func(g, k, *args, **kwargs)
     25             g[k].attrs.setdefault("encoding-type", spec.encoding_type)
     26             g[k].attrs.setdefault("encoding-version", spec.encoding_version)

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/methods.py in write_mapping(f, k, v, dataset_kwargs)
    279     g = f.create_group(k)
    280     for sub_k, sub_v in v.items():
--> 281         write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)
    282 
    283 

/usr/local/lib/python3.8/dist-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
    212     def func_wrapper(elem, key, val, *args, **kwargs):
    213         try:
--> 214             return func(elem, key, val, *args, **kwargs)
    215         except Exception as e:
    216             if "Above error raised while writing key" in format(e):

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in write_elem(f, k, elem, modifiers, *args, **kwargs)
    173         )
    174     else:
--> 175         _REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
    176 
    177 

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in wrapper(g, k, *args, **kwargs)
     22         @wraps(func)
     23         def wrapper(g, k, *args, **kwargs):
---> 24             result = func(g, k, *args, **kwargs)
     25             g[k].attrs.setdefault("encoding-type", spec.encoding_type)
     26             g[k].attrs.setdefault("encoding-version", spec.encoding_version)

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/methods.py in write_mapping(f, k, v, dataset_kwargs)
    279     g = f.create_group(k)
    280     for sub_k, sub_v in v.items():
--> 281         write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)
    282 
    283 

/usr/local/lib/python3.8/dist-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
    212     def func_wrapper(elem, key, val, *args, **kwargs):
    213         try:
--> 214             return func(elem, key, val, *args, **kwargs)
    215         except Exception as e:
    216             if "Above error raised while writing key" in format(e):

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in write_elem(f, k, elem, modifiers, *args, **kwargs)
    173         )
    174     else:
--> 175         _REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
    176 
    177 

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/registry.py in wrapper(g, k, *args, **kwargs)
     22         @wraps(func)
     23         def wrapper(g, k, *args, **kwargs):
---> 24             result = func(g, k, *args, **kwargs)
     25             g[k].attrs.setdefault("encoding-type", spec.encoding_type)
     26             g[k].attrs.setdefault("encoding-version", spec.encoding_version)

/usr/local/lib/python3.8/dist-packages/anndata/_io/specs/methods.py in write_mapping(f, k, v, dataset_kwargs)
    279     g = f.create_group(k)
    280     for sub_k, sub_v in v.items():
--> 281         write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)
    282 
    283 

/usr/local/lib/python3.8/dist-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
    218             else:
    219                 parent = _get_parent(elem)
--> 220                 raise type(e)(
    221                     f"{e}\n\n"
    222                     f"Above error raised while writing key {key!r} of {type(elem)} "

TypeError: No method has been defined for writing <enum 'VelocityMode'> elements to <class 'h5py._hl.group.Group'>

Above error raised while writing key 'mode' of <class 'h5py._hl.group.Group'> to /
```


Unfortunately the data is private and a lot of the workflow would be hard to replicate on your end for a variety of reasons. But the maybe a summary of the final anndata objects could help?
```
AnnData object with n_obs × n_vars = 1434 × 913
    obs: 'monaco__anno', 'diced__anno', 'pterotyping_donor__anno', 'monaco_clustered__anno', 'diced_clustered__anno', 'subentity__entity__sample__indication', 'subentity__entity__sample__tissue', 'decontx_est', 'soupx_est', 'doubletdetection_label', 'doubletidentifier_label', 'ptero_json__percent.mito', 'singler_json__percent.mito', 'subentity', 'batch', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'total_counts_ribo', 'pct_counts_ribo', 'total_counts_hb', 'pct_counts_hb', 'total_counts_hsp', 'pct_counts_hsp', 'initial_size_spliced', 'initial_size_unspliced', 'initial_size', 'n_counts', 'velocity_self_transition', 'louvain', 'leiden', 'terminal_states', 'terminal_states_probs', 'initial_states', 'initial_states_probs', 'S_score', 'G2M_score', 'phase', 'ct_num_exp_genes', 'ct_score', 'ct_pseudotime', 'dpt_pseudotime'
    var: 'mt', 'hsp', 'ribo', 'hb', 'n_cells_by_counts', 'mean_counts', 'pct_dropout_by_counts', 'total_counts', 'velocity_gamma', 'velocity_qreg_ratio', 'velocity_r2', 'velocity_genes', 'fit_alpha', 'fit_beta', 'fit_gamma', 'fit_t_', 'fit_scaling', 'fit_std_u', 'fit_std_s', 'fit_likelihood', 'fit_u0', 'fit_s0', 'fit_pval_steady', 'fit_steady_u', 'fit_steady_s', 'fit_variance', 'fit_alignment_scaling', 'spearmans_score', 'velocity_score', 'ct_gene_corr', 'ct_correlates'
    uns: 'pca', 'neighbors', 'velocity_params', 'velocity_graph', 'velocity_graph_neg', 'umap', 'louvain', 'leiden', 'recover_dynamics', 'T_fwd_params', 'eigendecomposition_fwd', 'terminal_states_colors', 'T_bwd_params', 'eigendecomposition_bwd', 'initial_states_colors', 'rank_velocity_genes', 'ct_params', 'diffmap_evals', 'pterotyping_donor__anno_colors', 'phase_colors', 'louvain_colors', 'doubletdetection_label_colors', 'doubletidentifier_label_colors', 'iroot', 'paga', 'pterotyping_donor__anno_sizes', 'subentity_colors'
    obsm: 'X_pca', 'X_umap', 'terminal_states_memberships', 'initial_states_memberships', 'to_terminal_states', 'X_phate', 'X_diffmap', 'velocity_phate', 'velocity_umap'
    varm: 'PCs', 'loss', 'terminal_lineage_drivers'
    layers: 'spliced', 'unspliced', 'Ms', 'Mu', 'velocity', 'variance_velocity', 'fit_t', 'fit_tau', 'fit_tau_'
    obsp: 'distances', 'connectivities', 'T_fwd', 'T_bwd'
```
@ivirshup, this isn't coming from scVelo but CellRank. So @michalk8 might be able to help.
`VelocityModel`  was introduced few weeks before in https://github.com/theislab/cellrank/pull/791 and is is both an `Enum` and a `str` (had hoped that being a `str` mixin would pose no problem, but failed to test for this). 
@michalk8, should this be addressed in cell rank? E.g. can I close this, or does something need to be done in anndata?
> @michalk8, should this be addressed in cell rank? E.g. can I close this, or does something need to be done in anndata?

Yes, I will save not the `Enum`, but `str`. Can you please transfer the issue to CellRank?

Fix patch:
diff --git a/cellrank/tl/kernels/_velocity_kernel.py b/cellrank/tl/kernels/_velocity_kernel.py
index 0edae4b24..e52e1058a 100644
--- a/cellrank/tl/kernels/_velocity_kernel.py
+++ b/cellrank/tl/kernels/_velocity_kernel.py
@@ -132,7 +132,7 @@ def compute_transition_matrix(
         start = logg.info(f"Computing transition matrix using `{model!r}` model")
 
         # fmt: off
-        params = {"model": model, "similarity": str(similarity), "softmax_scale": softmax_scale}
+        params = {"model": str(model), "similarity": str(similarity), "softmax_scale": softmax_scale}
         if self.backward:
             params["bwd_mode"] = str(backward_mode)
         if VelocityModel(model) == VelocityModel.MONTE_CARLO:


Test patch:
diff --git a/tests/test_kernels.py b/tests/test_kernels.py
index 406250aef..1933af659 100644
--- a/tests/test_kernels.py
+++ b/tests/test_kernels.py
@@ -17,6 +17,7 @@
 from scanpy import Neighbors
 from anndata import AnnData
 from cellrank._key import Key
+from cellrank.tl._enum import ModeEnum
 from cellrank.tl._utils import _normalize
 from cellrank.ul._utils import _get_neighs, _get_neighs_params
 from cellrank.tl.kernels import (
@@ -36,6 +37,7 @@
     UnidirectionalKernel,
 )
 from cellrank.tl.kernels._cytotrace_kernel import CytoTRACEAggregation
+from cellrank.tl.kernels.utils._velocity_model import VelocityModel
 
 import numpy as np
 import pandas as pd
@@ -1016,6 +1018,24 @@ def test_custom_function_stochastic_no_hessian(self, adata: AnnData):
         assert vk.params["model"] == "stochastic"
         assert vk.params["similarity"] == str(CustomFunc())
 
+    def test_save_to_anndata(self, adata: AnnData, tmpdir):
+        path = Path(tmpdir) / "adata.h5ad"
+        key = "vk"
+
+        vk = VelocityKernel(adata).compute_transition_matrix(
+            model=VelocityModel.DETERMINISTIC
+        )
+        vk.write_to_adata(key=key)
+
+        assert isinstance(vk.params["model"], str)
+        assert not isinstance(vk.params["model"], ModeEnum)
+        assert vk.params == adata.uns[f"{key}_params"]["params"]
+
+        sc.write(path, adata)
+
+        bdata = sc.read(path)
+        assert vk.params == bdata.uns[f"{key}_params"]["params"]
+
 
 class TestComputeProjection:
     def test_no_transition_matrix(self, adata: AnnData):