Skip to content

Commit

Permalink
fix(tests): update PCA test for sklearn version compatibility
Browse files Browse the repository at this point in the history
Added version check for scikit-learn in test_pca_feature_extractor to
handle differences in expected output based on version. This ensures
compatibility with scikit-learn versions 1.4.0 and above.
  • Loading branch information
psmyth94 committed Nov 18, 2024
1 parent 5a984da commit c51699f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/preprocessing/test_pca.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import biofit.config
import pandas as pd
import pytest
import sklearn
from biocore.data_handling import DataHandler
from biocore.utils.import_util import is_biosets_available
from biofit.preprocessing import PCAFeatureExtractor
from packaging import version

from tests.utils import create_bioset

Expand Down Expand Up @@ -32,7 +34,12 @@ def test_pca_feature_extractor(count_data, sample_metadata, format):
otu_dataset = pd.concat([sample_metadata, X, y], axis=1)

proc = PCAFeatureExtractor(load_from_cache_file=load_from_cache_file)
expected = [-0.37224401, 1.02218086, -1.25448252, -0.22033803, -0.2220483]
if version.parse(sklearn.__version__) >= version.parse("1.4.0"):
expected = [-0.37224401, 1.02218086, -1.25448252, -0.22033803, -0.2220483]
else:
# For some reason, the second to last value is positive in previous scikit-learn
# Probably due to how the sign of the eigenvectors is determined.
expected = [-0.37224401, 1.02218086, -1.25448252, 0.22033803, -0.2220483]

input_columns = list(X.columns)
cache_dir = biofit.config.BIOFIT_CACHE_HOME
Expand Down

0 comments on commit c51699f

Please sign in to comment.