From 2ff802bf73039f6014cb6fe61c6fd14aed660576 Mon Sep 17 00:00:00 2001 From: icfaust Date: Wed, 24 Jul 2024 07:17:49 -0700 Subject: [PATCH] updates for numpy2 issues --- .ci/scripts/get_compatible_scipy_version.py | 15 +++++++++++++-- .github/workflows/ci.yml | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.ci/scripts/get_compatible_scipy_version.py b/.ci/scripts/get_compatible_scipy_version.py index 82ec0a83fa..e74851ac42 100644 --- a/.ci/scripts/get_compatible_scipy_version.py +++ b/.ci/scripts/get_compatible_scipy_version.py @@ -14,10 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== -from sys import exit, stderr +from sys import argv, exit, stderr from sys import version_info as python_version -from daal4py.sklearn._utils import sklearn_check_version +if len(argv) == 1: + from daal4py.sklearn._utils import sklearn_check_version +else: + # This is necessary to prevent import errors from sklearnex and by extension + # sklearn caused by initial scipy and/or numpy versions that are installed. + # It is written in a way to be `packaging` independent. This branch occurs + # when a sklearn version is given to the script externally. + def sklearn_check_version(ver): + ver = [int(i) if i != "" else 0 for i in ver.split(".")] + sk_ver = [int(i) if i != "" else 0 for i in str(argv[1]).split(".")] + return sk_ver[0] > ver[0] or (sk_ver[0] == ver[0] and sk_ver[1] >= ver[1]) + if sklearn_check_version("1.4"): print("Scipy version is not specified for this sklearn/python version.", file=stderr) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56c04f6f68..aea7ef5ef1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,7 +88,7 @@ jobs: source .github/scripts/activate_components.sh bash .ci/scripts/setup_sklearn.sh ${{ matrix.SKLEARN_VERSION }} pip install --upgrade -r requirements-test.txt - pip install $(python .ci/scripts/get_compatible_scipy_version.py) pyyaml + pip install $(python .ci/scripts/get_compatible_scipy_version.py ${{ matrix.SKLEARN_VERSION }}) pyyaml if [ "${{ steps.set-env.outputs.DPCFLAG }}" == "" ]; then pip install dpctl==${{ env.DPCTL_VERSION }} dpnp==${{ env.DPNP_VERSION }}; fi pip list - name: Sklearnex testing @@ -222,7 +222,7 @@ jobs: call .\.github\scripts\activate_components.bat ${{ env.DPCPP_VERSION }} ${{ env.TBB_VERSION }} ${{ steps.set-env.outputs.DPCFLAG }} bash .ci/scripts/setup_sklearn.sh ${{ matrix.SKLEARN_VERSION }} pip install --upgrade -r requirements-test.txt - for /f "delims=" %%c in ('python .ci\scripts\get_compatible_scipy_version.py') do set SCIPY_VERSION=%%c + for /f "delims=" %%c in ('python .ci\scripts\get_compatible_scipy_version.py ${{ matrix.SKLEARN_VERSION }}') do set SCIPY_VERSION=%%c pip install %SCIPY_VERSION% if "${{ steps.set-env.outputs.DPCFLAG }}"=="" pip install dpctl==${{ env.DPCTL_VERSION }} dpnp==${{ env.DPNP_VERSION }} pip list