diff --git a/sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py b/sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py index c49bface8a..797caff2f8 100644 --- a/sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +++ b/sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py @@ -23,7 +23,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_statistic_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py b/sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py index 63060e4e9b..6cd93fe325 100644 --- a/sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py +++ b/sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py @@ -23,7 +23,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_statistic_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/cluster/tests/test_dbscan_spmd.py b/sklearnex/spmd/cluster/tests/test_dbscan_spmd.py index cc29261cfd..5d0a531dc4 100644 --- a/sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +++ b/sklearnex/spmd/cluster/tests/test_dbscan_spmd.py @@ -21,7 +21,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_clustering_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/cluster/tests/test_kmeans_spmd.py b/sklearnex/spmd/cluster/tests/test_kmeans_spmd.py index 3516a43d98..1b68bbbd2c 100644 --- a/sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +++ b/sklearnex/spmd/cluster/tests/test_kmeans_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _assert_kmeans_labels_allclose, _assert_unordered_allclose, _generate_clustering_data, diff --git a/sklearnex/spmd/covariance/tests/test_covariance_spmd.py b/sklearnex/spmd/covariance/tests/test_covariance_spmd.py index 9e3aac4094..1b97c831f5 100644 --- a/sklearnex/spmd/covariance/tests/test_covariance_spmd.py +++ b/sklearnex/spmd/covariance/tests/test_covariance_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_statistic_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py b/sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py index b371b67bb2..649d01e43d 100644 --- a/sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py +++ b/sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_statistic_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py b/sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py index 2857770855..776cabfa7b 100644 --- a/sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py +++ b/sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py @@ -23,7 +23,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_statistic_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/decomposition/tests/test_pca_spmd.py b/sklearnex/spmd/decomposition/tests/test_pca_spmd.py index 1bc28625b7..ba9682e0e9 100644 --- a/sklearnex/spmd/decomposition/tests/test_pca_spmd.py +++ b/sklearnex/spmd/decomposition/tests/test_pca_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_statistic_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/ensemble/tests/test_forest_spmd.py b/sklearnex/spmd/ensemble/tests/test_forest_spmd.py index 53aeffb5d7..9429b61189 100644 --- a/sklearnex/spmd/ensemble/tests/test_forest_spmd.py +++ b/sklearnex/spmd/ensemble/tests/test_forest_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_classification_data, _generate_regression_data, _get_local_tensor, diff --git a/sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py b/sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py index d8b11ce7ab..4db9975754 100644 --- a/sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py +++ b/sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py @@ -23,7 +23,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_regression_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py b/sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py index 01aef13157..0d50f5fef6 100644 --- a/sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +++ b/sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_regression_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py b/sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py index cd2f3984ec..bfe8203bab 100644 --- a/sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +++ b/sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py @@ -23,7 +23,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _generate_classification_data, _get_local_tensor, _mpi_libs_and_gpu_available, diff --git a/sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py b/sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py index a9272fab4e..24112a362e 100644 --- a/sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +++ b/sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py @@ -22,7 +22,7 @@ _convert_to_dataframe, get_dataframes_and_queues, ) -from sklearnex.tests._utils_spmd import ( +from sklearnex.tests.utils.spmd import ( _assert_unordered_allclose, _generate_classification_data, _generate_regression_data, diff --git a/sklearnex/tests/test_memory_usage.py b/sklearnex/tests/test_memory_usage.py index 666a0f08ee..012086507b 100644 --- a/sklearnex/tests/test_memory_usage.py +++ b/sklearnex/tests/test_memory_usage.py @@ -37,7 +37,7 @@ ) from onedal.tests.utils._device_selection import get_queues, is_dpctl_available from sklearnex import config_context -from sklearnex.tests._utils import PATCHED_FUNCTIONS, PATCHED_MODELS, SPECIAL_INSTANCES +from sklearnex.tests.utils import PATCHED_FUNCTIONS, PATCHED_MODELS, SPECIAL_INSTANCES from sklearnex.utils._array_api import get_namespace if _is_dpc_backend: diff --git a/sklearnex/tests/test_patching.py b/sklearnex/tests/test_patching.py index d7da20c89d..897f19172d 100755 --- a/sklearnex/tests/test_patching.py +++ b/sklearnex/tests/test_patching.py @@ -36,7 +36,7 @@ from sklearnex import is_patched_instance from sklearnex.dispatcher import _is_preview_enabled from sklearnex.metrics import pairwise_distances, roc_auc_score -from sklearnex.tests._utils import ( +from sklearnex.tests.utils import ( DTYPES, PATCHED_FUNCTIONS, PATCHED_MODELS, diff --git a/sklearnex/tests/test_run_to_run_stability.py b/sklearnex/tests/test_run_to_run_stability.py index 889dc0c6b6..f2e0560a27 100755 --- a/sklearnex/tests/test_run_to_run_stability.py +++ b/sklearnex/tests/test_run_to_run_stability.py @@ -21,14 +21,6 @@ import numpy as np import pytest -from _utils import ( - PATCHED_MODELS, - SPECIAL_INSTANCES, - _sklearn_clone_dict, - call_method, - gen_dataset, - gen_models_info, -) from numpy.testing import assert_allclose from scipy import sparse from sklearn.datasets import ( @@ -52,6 +44,14 @@ NearestNeighbors, ) from sklearnex.svm import SVC +from sklearnex.tests.utils import ( + PATCHED_MODELS, + SPECIAL_INSTANCES, + call_method, + gen_dataset, + gen_models_info, + sklearn_clone_dict, +) # to reproduce errors even in CI d4p.daalinit(nthreads=100) @@ -124,9 +124,9 @@ def _run_test(estimator, method, datasets): KMeans(init="k-means++"), ] ) -SPARSE_INSTANCES = _sklearn_clone_dict({str(i): i for i in _sparse_instances}) +SPARSE_INSTANCES = sklearn_clone_dict({str(i): i for i in _sparse_instances}) -STABILITY_INSTANCES = _sklearn_clone_dict( +STABILITY_INSTANCES = sklearn_clone_dict( { str(i): i for i in [ diff --git a/sklearnex/tests/utils/__init__.py b/sklearnex/tests/utils/__init__.py new file mode 100644 index 0000000000..785a44c87b --- /dev/null +++ b/sklearnex/tests/utils/__init__.py @@ -0,0 +1,41 @@ +# ============================================================================== +# Copyright 2024 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +from .base import ( + DTYPES, + PATCHED_FUNCTIONS, + PATCHED_MODELS, + SPECIAL_INSTANCES, + UNPATCHED_FUNCTIONS, + UNPATCHED_MODELS, + call_method, + gen_dataset, + gen_models_info, + sklearn_clone_dict, +) + +__all__ = [ + "DTYPES", + "PATCHED_FUNCTIONS", + "PATCHED_MODELS", + "UNPATCHED_FUNCTIONS", + "UNPATCHED_MODELS", + "SPECIAL_INSTANCES", + "call_method", + "gen_models_info", + "gen_dataset", + "sklearn_clone_dict", +] diff --git a/sklearnex/tests/_utils.py b/sklearnex/tests/utils/base.py similarity index 99% rename from sklearnex/tests/_utils.py rename to sklearnex/tests/utils/base.py index 413747a1a9..c1b06e8675 100755 --- a/sklearnex/tests/_utils.py +++ b/sklearnex/tests/utils/base.py @@ -106,7 +106,7 @@ def _load_all_models(with_sklearnex=True, estimator=True): ] -class _sklearn_clone_dict(dict): +class sklearn_clone_dict(dict): """Special dict type for returning state-free sklearn/sklearnex estimators with the same parameters""" @@ -118,7 +118,7 @@ def __getitem__(self, key): # could be because of supported non-default parameters, blocked support via sklearn's # 'available_if' decorator, or not being a native sklearn estimator (i.e. those not in # the default PATCHED_MODELS dictionary) -SPECIAL_INSTANCES = _sklearn_clone_dict( +SPECIAL_INSTANCES = sklearn_clone_dict( { str(i): i for i in [ diff --git a/sklearnex/tests/_utils_spmd.py b/sklearnex/tests/utils/spmd.py similarity index 100% rename from sklearnex/tests/_utils_spmd.py rename to sklearnex/tests/utils/spmd.py