From c9d34abddfba57f309e5997672e8f188daa93e7b Mon Sep 17 00:00:00 2001 From: Tony Bagnall Date: Sat, 12 Jul 2025 20:22:38 +0100 Subject: [PATCH] SFA testing for coverage --- .../collection/dictionary_based/_sfa.py | 7 ---- .../dictionary_based/tests/test_sfa.py | 34 +++++++++++++++++-- .../transformations/series/tests/test_base.py | 17 ++++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/aeon/transformations/collection/dictionary_based/_sfa.py b/aeon/transformations/collection/dictionary_based/_sfa.py index b862c280db..dace853243 100644 --- a/aeon/transformations/collection/dictionary_based/_sfa.py +++ b/aeon/transformations/collection/dictionary_based/_sfa.py @@ -280,9 +280,6 @@ def _transform(self, X, y=None): List of dictionaries containing SFA words """ X = X.squeeze(1) - - # with warnings.catch_warnings(): - # warnings.simplefilter("ignore", category=NumbaTypeSafetyWarning) transform = Parallel(n_jobs=self._n_jobs, prefer="threads")( delayed(self._transform_case)( X[i, :], @@ -327,10 +324,6 @@ def transform_mft(self, X): ------- Array of Fourier coefficients """ - # X = X.squeeze(1) - - # with warnings.catch_warnings(): - # warnings.simplefilter("ignore", category=NumbaTypeSafetyWarning) transform = Parallel(n_jobs=self._n_jobs, prefer="threads")( delayed(self._mft)(X[i, :]) for i in range(X.shape[0]) ) diff --git a/aeon/transformations/collection/dictionary_based/tests/test_sfa.py b/aeon/transformations/collection/dictionary_based/tests/test_sfa.py index 1ec2aba892..55272b3375 100644 --- a/aeon/transformations/collection/dictionary_based/tests/test_sfa.py +++ b/aeon/transformations/collection/dictionary_based/tests/test_sfa.py @@ -6,6 +6,9 @@ import pytest from aeon.datasets import load_unit_test +from aeon.testing.data_generation import ( + make_example_3d_numpy, +) from aeon.transformations.collection.dictionary_based import SFA, SFAFast @@ -92,9 +95,6 @@ def test_dft_mft(use_fallback_dft, norm): assert len(mft[0]) == word_length -test_dft_mft(True, True) - - @pytest.mark.parametrize("binning_method", ["equi-depth", "information-gain"]) def test_sfa_anova(binning_method): """Test the SFA transformer with ANOVA one-sided test.""" @@ -249,3 +249,31 @@ def test_sfa_fast_transform_after_fit(): and np.all(x.indptr == y.indptr) and np.allclose(x.data, y.data) ) + + +def test_incorrect_paras(): + """Test incorrect parameters in SFA.""" + X, y = make_example_3d_numpy(n_cases=20, n_channels=1, n_timepoints=49) + sfa = SFA(alphabet_size=1, word_length=0, binning_method="information-gain") + with pytest.raises(ValueError, match="must be an integer greater than 2"): + sfa._fit(X) + sfa.alphabet_size = 4 + with pytest.raises(ValueError, match="must be an integer greater than 1"): + sfa._fit(X) + sfa.word_length = 2 + with pytest.raises(ValueError, match="Class values must be provided"): + sfa._fit(X) + sfa.binning_method = "Arsenal" + with pytest.raises(TypeError, match="binning_method must be one of"): + sfa._fit(X) + sfa = SFA(word_length=64, alphabet_size=8) + sfa.max_bits = 128 + sfa._typed_dict = True + with pytest.raises(ValueError, match="Typed Dictionaries can only handle 64 bit"): + sfa._fit(X, y) + sfa = SFA(typed_dict=True, levels=16) + with pytest.raises(ValueError, match="Dictionaries can only handle 15 levels"): + sfa._fit(X, y) + sfa = SFA(typed_dict=True, save_words=True, n_jobs=2) + sfa.fit_transform(X, y) + assert isinstance(sfa.words, np.ndarray) diff --git a/aeon/transformations/series/tests/test_base.py b/aeon/transformations/series/tests/test_base.py index 76aed38f03..7ed6779ebd 100644 --- a/aeon/transformations/series/tests/test_base.py +++ b/aeon/transformations/series/tests/test_base.py @@ -3,6 +3,10 @@ import numpy as np import pytest +from aeon.testing.data_generation import ( + make_example_1d_numpy, + make_example_2d_numpy_series, +) from aeon.testing.mock_estimators import ( MockMultivariateSeriesTransformer, MockSeriesTransformerNoFit, @@ -53,3 +57,16 @@ def test_fit_transform_univariate(): x3 = transformer.transform(x1, x2) x4 = transformer.fit_transform(x1, x2) np.testing.assert_array_almost_equal(x3, x4) + + +def test_check_y(): + """Test check_y function in BaseTransformer.""" + y = make_example_2d_numpy_series(100, 3) + t = MockSeriesTransformerNoFit() + with pytest.raises(TypeError, match="must be a np.array or a pd.Series"): + t._check_y("Arsenal") + with pytest.raises(TypeError, match="must be 1-dimensional"): + t._check_y(y) + y = make_example_1d_numpy(100) + with pytest.raises(ValueError, match="Mismatch in number of cases"): + t._check_y(y, 50)