From aef013114e5d9106a82e243e384301cbed451ece Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Fri, 9 Dec 2022 13:35:16 +0100 Subject: [PATCH 01/12] MNT drop python=3.7 support --- .github/workflows/build-test.yml | 11 ++++---- pyproject.toml | 2 +- setup.py | 6 ++--- skops/hub_utils/tests/test_hf_hub.py | 12 ++++----- skops/utils/fixes.py | 37 ------------------------- skops/utils/tests/test_fixes.py | 40 ---------------------------- 6 files changed, 16 insertions(+), 92 deletions(-) delete mode 100644 skops/utils/tests/test_fixes.py diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 25066be1..5fe8c6d1 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -17,18 +17,19 @@ jobs: fail-fast: false # need to see which ones fail matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python: ["3.7", "3.8", "3.9", "3.10"] + python: ["3.8", "3.9", "3.10", "3.11"] # this is to make the CI run on different sklearn versions include: - - python: "3.7" - sklearn_version: "0.24.0" - python: "3.8" - sklearn_version: "1.0.0" + sklearn_version: "1.0" - python: "3.9" - sklearn_version: "1.1.0" + sklearn_version: "1.1" - python: "3.10" + sklearn_version: "1.2" + - python: "3.11" sklearn_version: "nightly" + # Timeout: https://stackoverflow.com/a/59076067/4521646 timeout-minutes: 15 diff --git a/pyproject.toml b/pyproject.toml index b19d1aa4..2ee0d477 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.black] line-length = 88 -target_version = ['py37', 'py38', 'py39', 'py310'] +target_version = ['py38', 'py39', 'py310', 'py311'] preview = true [tool.isort] diff --git a/setup.py b/setup.py index df25333b..69d800a5 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ # This is a bit (!) hackish: we are setting a global variable so that the # main modelcard __init__ can detect if it is being loaded by the setup # routine, to avoid attempting to load components. -builtins.__SKOPS_SETUP__ = True +builtins.__SKOPS_SETUP__ = True # type: ignore import skops # noqa @@ -58,13 +58,13 @@ def setup_package(): "Operating System :: Unix", "Operating System :: MacOS", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", ], - python_requires=">=3.7", + python_requires=">=3.8", install_requires=min_deps.tag_to_packages["install"], extras_require={ "docs": min_deps.tag_to_packages["docs"], diff --git a/skops/hub_utils/tests/test_hf_hub.py b/skops/hub_utils/tests/test_hf_hub.py index 5aa229d1..7e3033f3 100644 --- a/skops/hub_utils/tests/test_hf_hub.py +++ b/skops/hub_utils/tests/test_hf_hub.py @@ -36,7 +36,7 @@ _validate_folder, ) from skops.hub_utils.tests.common import HF_HUB_TOKEN -from skops.utils.fixes import metadata, path_unlink +from skops.utils.fixes import metadata iris = load_iris(as_frame=True, return_X_y=False) diabetes = load_diabetes(as_frame=True, return_X_y=False) @@ -85,7 +85,7 @@ def classifier_pickle(repo_path): pickle.dump(clf, f) yield path finally: - path_unlink(path, missing_ok=True) + path.unlink(missing_ok=True) CONFIG = { @@ -104,7 +104,7 @@ def config_json(repo_path): json.dump(CONFIG, f) yield path finally: - path_unlink(path, missing_ok=True) + path.unlink(missing_ok=True) def test_validate_folder(config_json): @@ -304,7 +304,7 @@ def test_model_file_does_not_exist_raises(repo_path, config_json): task="tabular-classification", data=iris.data, ) - path_unlink(model_path, missing_ok=True) + model_path.unlink(missing_ok=True) def test_init_empty_model_file_errors(repo_path, config_json): @@ -326,7 +326,7 @@ def test_init_empty_model_file_errors(repo_path, config_json): task="tabular-classification", data=iris.data, ) - path_unlink(model_path, missing_ok=True) + model_path.unlink(missing_ok=True) @pytest.mark.network @@ -459,7 +459,7 @@ def test_inference( # cleanup client.delete_repo(repo_id=repo_id, token=HF_HUB_TOKEN) - path_unlink(model_path, missing_ok=True) + model_path.unlink(missing_ok=True) assert np.allclose(output, y_pred) diff --git a/skops/utils/fixes.py b/skops/utils/fixes.py index e9d83558..11fee9c7 100644 --- a/skops/utils/fixes.py +++ b/skops/utils/fixes.py @@ -2,8 +2,6 @@ # versions of a dependency. import sys -from contextlib import suppress -from pathlib import Path if sys.version_info >= (3, 8): # py>=3.8 @@ -20,38 +18,3 @@ # if you're removing this, you should also remove the dependency from # _min_dependencies.py from typing_extensions import Literal # noqa - - -def path_unlink(path: Path, missing_ok: bool = False) -> None: - """Remove this file or symbolic link - - Parameters - ---------- - path : pathlib.Path - Path to the file to be removed - - missing_ok : bool (default=False) - If False, ``FileNotFoundError`` is raised if the path does not exist. If - True, ``FileNotFoundError`` exceptions will be ignored (same behavior as - the POSIX ``rm -f`` command). - - Raises - ------ - FileNotFoundError - Is raised if ``missing_ok`` is False and the file is missing. - - """ - # Python 3.7 does not support the missing_ok argument. - # One we move to Python >= 3.8, this function can just call - # Path.unlink(missing_ok) - if not missing_ok: # default behavior - path.unlink() - return - - if sys.version_info >= (3, 8): - path.unlink(missing_ok=missing_ok) - return - - # for Python 3.7, just catch the error - with suppress(FileNotFoundError): - path.unlink() diff --git a/skops/utils/tests/test_fixes.py b/skops/utils/tests/test_fixes.py deleted file mode 100644 index 2a1d9991..00000000 --- a/skops/utils/tests/test_fixes.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Tests for skops.utils.fixes.py""" - -import tempfile -from pathlib import Path - -import pytest - - -class TestPathUnlink: - @pytest.fixture(scope="class") - def path_unlink(self): - from skops.utils.fixes import path_unlink - - return path_unlink - - @pytest.fixture(scope="class") - def tempdir(self): - with tempfile.TemporaryDirectory(prefix="skops-test") as directory: - yield Path(directory) - - def test_path_unlink_file_exists(self, path_unlink, tempdir): - path = tempdir / "some-file" - path.touch() - assert path.exists() - - path_unlink(path) - assert not path.exists() - - def test_path_unlink_file_does_not_exist_raises(self, path_unlink, tempdir): - path = tempdir / "some-file" - assert not path.exists() - - with pytest.raises(FileNotFoundError): - path_unlink(path) - - def test_path_unlink_file_does_not_missing_ok(self, path_unlink, tempdir): - path = tempdir / "some-file" - assert not path.exists() - # does not raise an error - path_unlink(path, missing_ok=True) From 8a64e422f8a6ebfd38b61da1e3998aa5e07e5bcb Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Mon, 12 Dec 2022 11:38:16 +0100 Subject: [PATCH 02/12] add futurewarning to the list of ignored ones --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 2ee0d477..fdc272a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,8 @@ filterwarnings = [ "ignore:The \\'sym_pos\\' keyword is deprecated and should be replaced:DeprecationWarning", # https://github.com/scikit-learn/scikit-learn/pull/23633 "ignore:Unlike other reduction functions:FutureWarning", + # https://github.com/scikit-learn/scikit-learn/pull/25157 + "ignore:open_text is deprecated:FutureWarning", ] markers = [ "network: marks tests as requiring internet (deselect with '-m \"not network\"')", From 7fd557c30f2a30d9ffa0d71e3f22cc6c1529356e Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Mon, 12 Dec 2022 15:43:30 +0100 Subject: [PATCH 03/12] it's a DeprecationWarning --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fdc272a7..be7c59cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ filterwarnings = [ # https://github.com/scikit-learn/scikit-learn/pull/23633 "ignore:Unlike other reduction functions:FutureWarning", # https://github.com/scikit-learn/scikit-learn/pull/25157 - "ignore:open_text is deprecated:FutureWarning", + "ignore:open_text is deprecated:DeprecationWarning", ] markers = [ "network: marks tests as requiring internet (deselect with '-m \"not network\"')", From 00a3917d995b258b08a2a147a374a61fb32247b7 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 13 Dec 2022 12:06:35 +0100 Subject: [PATCH 04/12] change message --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index be7c59cc..c2a37115 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ filterwarnings = [ # https://github.com/scikit-learn/scikit-learn/pull/23633 "ignore:Unlike other reduction functions:FutureWarning", # https://github.com/scikit-learn/scikit-learn/pull/25157 - "ignore:open_text is deprecated:DeprecationWarning", + "ignore:Use files\(\) instead:DeprecationWarning", ] markers = [ "network: marks tests as requiring internet (deselect with '-m \"not network\"')", From b371b560d2eadcec76b3de514acdba7604583341 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 13 Dec 2022 13:12:51 +0100 Subject: [PATCH 05/12] try again --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c2a37115..4420fe59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ filterwarnings = [ # https://github.com/scikit-learn/scikit-learn/pull/23633 "ignore:Unlike other reduction functions:FutureWarning", # https://github.com/scikit-learn/scikit-learn/pull/25157 - "ignore:Use files\(\) instead:DeprecationWarning", + "ignore:Use files() instead:DeprecationWarning", ] markers = [ "network: marks tests as requiring internet (deselect with '-m \"not network\"')", From 6d63c102b7c8cfed271579de76b0ce8ca030e045 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 13 Dec 2022 14:32:10 +0100 Subject: [PATCH 06/12] use Ben's suggestion --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4420fe59..c957920e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ filterwarnings = [ # https://github.com/scikit-learn/scikit-learn/pull/23633 "ignore:Unlike other reduction functions:FutureWarning", # https://github.com/scikit-learn/scikit-learn/pull/25157 - "ignore:Use files() instead:DeprecationWarning", + "ignore:\\w+ is deprecated. Use files\\(\\) instead:DeprecationWarning" ] markers = [ "network: marks tests as requiring internet (deselect with '-m \"not network\"')", From 5a1754ee405c24ead896448b85a8a60571d1f2f3 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 14 Dec 2022 14:16:27 +0100 Subject: [PATCH 07/12] remove 311 --- .github/workflows/build-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 5fe8c6d1..785b6f8d 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false # need to see which ones fail matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python: ["3.8", "3.9", "3.10", "3.11"] + python: ["3.8", "3.9", "3.10"] # this is to make the CI run on different sklearn versions include: - python: "3.8" @@ -26,7 +26,7 @@ jobs: sklearn_version: "1.1" - python: "3.10" sklearn_version: "1.2" - - python: "3.11" + - python: "3.10" sklearn_version: "nightly" From 4fa26517cbe60b8df18f4710a5ba6f34fe2a5560 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 14 Dec 2022 14:17:47 +0100 Subject: [PATCH 08/12] add missing changes --- setup.py | 1 - skops/_min_dependencies.py | 1 - 2 files changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 69d800a5..2262dcea 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,6 @@ def setup_package(): "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", ], python_requires=">=3.8", diff --git a/skops/_min_dependencies.py b/skops/_min_dependencies.py index a3f1ced7..d67abb3d 100644 --- a/skops/_min_dependencies.py +++ b/skops/_min_dependencies.py @@ -26,7 +26,6 @@ "sphinx-issues": ("1.2.0", "docs", None), "matplotlib": ("3.3", "docs, tests", None), "pandas": ("1", "docs, tests", None), - "typing_extensions": ("3.7", "install", "python_full_version < '3.8'"), } From 716306b179bc1689efb19c92c93cff1eba1fdee2 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 14 Dec 2022 14:33:51 +0100 Subject: [PATCH 09/12] trying something --- .github/workflows/build-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 785b6f8d..a9ead16b 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -18,6 +18,8 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python: ["3.8", "3.9", "3.10"] + # just to make the following "include" section create the write matrix + sklearn_version: [] # this is to make the CI run on different sklearn versions include: - python: "3.8" From 05c522fae2cad9e31f115a47b70211d9a8e9065a Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 14 Dec 2022 14:40:03 +0100 Subject: [PATCH 10/12] trying something --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a9ead16b..2ddc067f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -19,7 +19,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] python: ["3.8", "3.9", "3.10"] # just to make the following "include" section create the write matrix - sklearn_version: [] + sklearn_version: [1.2] # this is to make the CI run on different sklearn versions include: - python: "3.8" From b0e8cb607aed1cde675c556bc6abb6283927a494 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 14 Dec 2022 14:44:59 +0100 Subject: [PATCH 11/12] remove fixes and fix the matri --- .github/workflows/build-test.yml | 5 +---- skops/utils/fixes.py | 20 -------------------- 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 skops/utils/fixes.py diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 2ddc067f..a7b704f8 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -18,15 +18,12 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python: ["3.8", "3.9", "3.10"] - # just to make the following "include" section create the write matrix - sklearn_version: [1.2] # this is to make the CI run on different sklearn versions include: - python: "3.8" sklearn_version: "1.0" + # TODO: add sklearn 1.1 when we add 3.11 support - python: "3.9" - sklearn_version: "1.1" - - python: "3.10" sklearn_version: "1.2" - python: "3.10" sklearn_version: "nightly" diff --git a/skops/utils/fixes.py b/skops/utils/fixes.py deleted file mode 100644 index 11fee9c7..00000000 --- a/skops/utils/fixes.py +++ /dev/null @@ -1,20 +0,0 @@ -# This file includes fixes which are usually required to handle multiple -# versions of a dependency. - -import sys - -if sys.version_info >= (3, 8): - # py>=3.8 - from importlib import metadata # noqa -else: - # older pythons - import importlib_metadata as metadata # noqa - -if sys.version_info >= (3, 8): - # py>=3.8 - from typing import Literal # noqa -else: - # older pythons, this requires typing_extensions to be installed. - # if you're removing this, you should also remove the dependency from - # _min_dependencies.py - from typing_extensions import Literal # noqa From 058fd171c00e59b44ac36586cd7f954ab9923370 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 14 Dec 2022 14:50:27 +0100 Subject: [PATCH 12/12] more fixes --- skops/hub_utils/_hf_hub.py | 4 +--- skops/hub_utils/tests/test_hf_hub.py | 2 +- skops/io/_audit.py | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/skops/hub_utils/_hf_hub.py b/skops/hub_utils/_hf_hub.py index 67d982a9..d76e1de3 100644 --- a/skops/hub_utils/_hf_hub.py +++ b/skops/hub_utils/_hf_hub.py @@ -9,13 +9,11 @@ import os import shutil from pathlib import Path -from typing import Any, List, MutableMapping, Optional, Union +from typing import Any, List, Literal, MutableMapping, Optional, Union import numpy as np from huggingface_hub import HfApi, InferenceApi, snapshot_download -from ..utils.fixes import Literal - SUPPORTED_TASKS = [ "tabular-classification", "tabular-regression", diff --git a/skops/hub_utils/tests/test_hf_hub.py b/skops/hub_utils/tests/test_hf_hub.py index ccb7d7c9..c4db9aee 100644 --- a/skops/hub_utils/tests/test_hf_hub.py +++ b/skops/hub_utils/tests/test_hf_hub.py @@ -5,6 +5,7 @@ import shutil import tempfile import warnings +from importlib import metadata from pathlib import Path from uuid import uuid4 @@ -37,7 +38,6 @@ ) from skops.hub_utils.tests.common import HF_HUB_TOKEN from skops.io import dump -from skops.utils.fixes import metadata iris = load_iris(as_frame=True, return_X_y=False) diabetes = load_diabetes(as_frame=True, return_X_y=False) diff --git a/skops/io/_audit.py b/skops/io/_audit.py index cb202cde..1e379308 100644 --- a/skops/io/_audit.py +++ b/skops/io/_audit.py @@ -2,9 +2,8 @@ import io from contextlib import contextmanager -from typing import Any, Generator, Sequence, Type, Union +from typing import Any, Generator, Literal, Sequence, Type, Union -from ..utils.fixes import Literal from ._trusted_types import PRIMITIVE_TYPE_NAMES from ._utils import LoadContext, get_module, get_type_paths from .exceptions import UntrustedTypesFoundException