From 6eb1064075922288180cee31b04f9fe5b307a2c8 Mon Sep 17 00:00:00 2001 From: Arber Qoku Date: Thu, 6 Jun 2024 18:25:26 +0200 Subject: [PATCH] Fix `variance_explained_grouped` --- muvi/tools/plotting.py | 9 +++++++-- muvi/tools/utils.py | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/muvi/tools/plotting.py b/muvi/tools/plotting.py index ddf84d1..8581194 100755 --- a/muvi/tools/plotting.py +++ b/muvi/tools/plotting.py @@ -158,8 +158,13 @@ def variance_explained( """Heatmap of variance explained, see `muvi.tl.variance_explained`.""" model_cache = _get_model_cache(model) - r2_fac = model_cache.factor_metadata - r2_cov = model_cache.cov_metadata + r2_fac = None + if model_cache.factor_metadata is not None: + r2_fac = model_cache.factor_metadata.copy() + r2_cov = None + if model_cache.cov_metadata is not None: + r2_cov = model_cache.cov_metadata.copy() + if r2_fac is None and r2_cov is None: raise ValueError( "No scores found in model cache, rerun `muvi.tl.variance_explained`." diff --git a/muvi/tools/utils.py b/muvi/tools/utils.py index c70aecb..5695c08 100644 --- a/muvi/tools/utils.py +++ b/muvi/tools/utils.py @@ -415,8 +415,10 @@ def variance_explained_grouped(model, groupby, factor_idx: Index = "all", **kwar model, sample_idx=group_df.index, factor_idx=factor_idx, + cache=False, + sort=False, **kwargs, - )[1] + )[1].copy() ) .reset_index() )