From f346a797d57c5b450e583ff4d465576d836e9986 Mon Sep 17 00:00:00 2001 From: RMeneses99 <124743604+RMeneses99@users.noreply.github.com> Date: Mon, 20 Apr 2026 15:32:55 +0200 Subject: [PATCH] Replace lazy loading of vectorize_counts_and_tree --- gemelli/preprocessing.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gemelli/preprocessing.py b/gemelli/preprocessing.py index 5e40888..ce1928b 100755 --- a/gemelli/preprocessing.py +++ b/gemelli/preprocessing.py @@ -21,7 +21,6 @@ from inspect import getfullargspec from gemelli._defaults import DEFAULT_MTD from skbio.stats.composition import clr -from skbio.diversity._util import _vectorize_counts_and_tree from bp import parse_newick, to_skbio_treenode from scipy.sparse.linalg import svds # import QIIME2 if in a Q2env otherwise set type to str @@ -627,13 +626,23 @@ def fast_unifrac(table, tree): TODO """ + + # Lazy Loading + try: + from skbio.diversity._util import vectorize_counts_and_tree + except ImportError: + raise ImportError( + "Could not import vectorize_counts_and_tree from skbio.diversity._util. " + "This function was made public in scikit-bio >= 0.6. " + "Please upgrade scikit-bio: pip install 'scikit-bio>=0.6'" + ) # original table bt_array = table.matrix_data.toarray() otu_ids = table.ids('observation') # expand the vectorized table counts_by_node, tree_index, branch_lengths \ - = _vectorize_counts_and_tree(bt_array.T, otu_ids, tree) + = vectorize_counts_and_tree(bt_array.T, otu_ids, tree) # check branch lengths if sum(branch_lengths) == 0: raise ValueError('All tree branch lengths are zero. '