From 4a66c9a50b7a4f0c5a3d17b547080490b26dd171 Mon Sep 17 00:00:00 2001 From: Ashar Ali Date: Thu, 3 Sep 2026 13:38:32 -0400 Subject: [PATCH] docs: document the `adata.uns['hvg']` output of `pp.highly_variable_genes` `highly_variable_genes` writes `adata.uns['hvg'] = {'flavor': flavor}` when `inplace=True`, on both the dispersion-based and the seurat_v3 paths, but the `Returns` section lists only the `adata.var` columns. The entry is part of the contract with downstream code rather than incidental bookkeeping: `pl.highly_variable_genes` reads `adata.uns['hvg']['flavor']` to choose whether to plot dispersions or variances, in both the legacy and the holoviews backends, and raises `KeyError: 'hvg'` without it. Closes #4341 Signed-off-by: Ashar Ali --- src/scanpy/preprocessing/_highly_variable_genes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/scanpy/preprocessing/_highly_variable_genes.py b/src/scanpy/preprocessing/_highly_variable_genes.py index 0f8f77d996..715e99e4aa 100644 --- a/src/scanpy/preprocessing/_highly_variable_genes.py +++ b/src/scanpy/preprocessing/_highly_variable_genes.py @@ -757,6 +757,10 @@ def highly_variable_genes( # noqa: PLR0913 If `batch_key` is given, this denotes in how many batches genes are detected as HVG `adata.var['highly_variable_intersection']` : :class:`pandas.Series` (dtype `bool`) If `batch_key` is given, this denotes the genes that are highly variable in all batches + `adata.uns['hvg']` : :class:`dict` + Dictionary with a `'flavor'` entry recording the `flavor` used. + :func:`scanpy.pl.highly_variable_genes` reads it to decide whether to plot + dispersions or variances """ if isinstance(flavor, Default):