From 4a038c73ecde9d5e7f4fcd8786923de641ca2647 Mon Sep 17 00:00:00 2001 From: Auguste Baum Date: Tue, 14 Jan 2025 11:05:26 +0100 Subject: [PATCH] chore: Replace all `|` in typehints with `typing.Union` --- skore/src/skore/externals/_sklearn_compat.py | 20 +++++++++---------- skore/src/skore/item/cross_validation_item.py | 12 +++++------ skore/src/skore/item/item.py | 8 ++++---- skore/src/skore/item/item_repository.py | 2 +- skore/src/skore/item/media_item.py | 10 +++++----- skore/src/skore/item/numpy_array_item.py | 10 +++++----- skore/src/skore/item/pandas_dataframe_item.py | 10 +++++----- skore/src/skore/item/pandas_series_item.py | 10 +++++----- skore/src/skore/item/polars_dataframe_item.py | 10 +++++----- skore/src/skore/item/polars_series_item.py | 10 +++++----- skore/src/skore/item/primitive_item.py | 10 +++++----- .../skore/item/sklearn_base_estimator_item.py | 10 +++++----- 12 files changed, 61 insertions(+), 61 deletions(-) diff --git a/skore/src/skore/externals/_sklearn_compat.py b/skore/src/skore/externals/_sklearn_compat.py index 2193e6812..226a89416 100644 --- a/skore/src/skore/externals/_sklearn_compat.py +++ b/skore/src/skore/externals/_sklearn_compat.py @@ -18,7 +18,7 @@ import sys import types from dataclasses import dataclass, field -from typing import Callable, Literal +from typing import Callable, Literal, Union import sklearn from sklearn.utils.fixes import parse_version @@ -775,11 +775,11 @@ class Tags: The input data(X) tags. """ - estimator_type: str | None + estimator_type: Union[str, None] target_tags: TargetTags - transformer_tags: TransformerTags | None = None - classifier_tags: ClassifierTags | None = None - regressor_tags: RegressorTags | None = None + transformer_tags: Union[TransformerTags, None] = None + classifier_tags: Union[ClassifierTags, None] = None + regressor_tags: Union[RegressorTags, None] = None array_api_support: bool = False no_validation: bool = False non_deterministic: bool = False @@ -808,10 +808,10 @@ def check_estimator( generate_only=False, *, legacy: bool = True, - expected_failed_checks: dict[str, str] | None = None, - on_skip: Literal["warn"] | None = "warn", - on_fail: Literal["raise", "warn"] | None = "raise", - callback: Callable | None = None, + expected_failed_checks: Union[dict[str, str], None] = None, + on_skip: Union[Literal["warn"], None] = "warn", + on_fail: Union[Literal["raise", "warn"], None] = "raise", + callback: Union[Callable, None] = None, ): # legacy, on_skip, on_fail, and callback are not supported and ignored from sklearn.utils.estimator_checks import check_estimator @@ -825,7 +825,7 @@ def parametrize_with_checks( estimators, *, legacy: bool = True, - expected_failed_checks: Callable | None = None, + expected_failed_checks: Union[Callable, None] = None, ): # legacy is not supported and ignored from sklearn.utils.estimator_checks import parametrize_with_checks diff --git a/skore/src/skore/item/cross_validation_item.py b/skore/src/skore/item/cross_validation_item.py index 026a442c6..13c26b0d4 100644 --- a/skore/src/skore/item/cross_validation_item.py +++ b/skore/src/skore/item/cross_validation_item.py @@ -14,7 +14,7 @@ import re import statistics from functools import cached_property -from typing import TYPE_CHECKING, Any, Literal, TypedDict +from typing import TYPE_CHECKING, Any, Literal, TypedDict, Union import numpy import plotly.graph_objects @@ -136,12 +136,12 @@ def __init__( cv_results_serialized: dict, estimator_info: EstimatorInfo, X_info: dict, - y_info: dict | None, + y_info: Union[dict, None], plots_bytes: dict[str, bytes], cv_info: dict, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a CrossValidationItem. @@ -167,7 +167,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/item.py b/skore/src/skore/item/item.py index 1aecc0bb4..0a7311912 100644 --- a/skore/src/skore/item/item.py +++ b/skore/src/skore/item/item.py @@ -30,11 +30,11 @@ class Item(ABC): Parameters ---------- - created_at : str | None, optional + created_at : Union[str, None], optional The creation timestamp of the item. If None, the current time is used. - updated_at : str | None, optional + updated_at : Union[str, None], optional The last update timestamp of the item. If None, the current time is used. - note : str | None + note : Union[str, None] An optional note. Attributes @@ -43,7 +43,7 @@ class Item(ABC): The creation timestamp of the item. updated_at : str The last update timestamp of the item. - note : str | None + note : Union[str, None] An optional note. """ diff --git a/skore/src/skore/item/item_repository.py b/skore/src/skore/item/item_repository.py index 6ebfc0f05..5b342ce31 100644 --- a/skore/src/skore/item/item_repository.py +++ b/skore/src/skore/item/item_repository.py @@ -184,7 +184,7 @@ def set_item_note(self, key: str, message: str, *, version=-1): except IndexError as e: raise KeyError((key, version)) from e - def get_item_note(self, key: str, *, version=-1) -> str | None: + def get_item_note(self, key: str, *, version=-1) -> Union[str, None]: """Retrieve a note previously attached to key ``key``. Parameters diff --git a/skore/src/skore/item/media_item.py b/skore/src/skore/item/media_item.py index de7430517..23ed45258 100644 --- a/skore/src/skore/item/media_item.py +++ b/skore/src/skore/item/media_item.py @@ -7,7 +7,7 @@ import base64 from io import BytesIO -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Union from skore.item.item import Item, ItemTypeError @@ -37,9 +37,9 @@ def __init__( media_bytes: bytes, media_encoding: str, media_type: str, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a MediaItem. @@ -56,7 +56,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str, optional The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/numpy_array_item.py b/skore/src/skore/item/numpy_array_item.py index ed1316814..c7e4a7251 100644 --- a/skore/src/skore/item/numpy_array_item.py +++ b/skore/src/skore/item/numpy_array_item.py @@ -7,7 +7,7 @@ from functools import cached_property from json import dumps, loads -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from skore.item.item import Item, ItemTypeError @@ -25,9 +25,9 @@ class NumpyArrayItem(Item): def __init__( self, array_json: str, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a NumpyArrayItem. @@ -40,7 +40,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/pandas_dataframe_item.py b/skore/src/skore/item/pandas_dataframe_item.py index b593f4324..3bd125431 100644 --- a/skore/src/skore/item/pandas_dataframe_item.py +++ b/skore/src/skore/item/pandas_dataframe_item.py @@ -7,7 +7,7 @@ from __future__ import annotations from functools import cached_property -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from skore.item.item import Item, ItemTypeError @@ -29,9 +29,9 @@ def __init__( self, index_json: str, dataframe_json: str, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a PandasDataFrameItem. @@ -46,7 +46,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/pandas_series_item.py b/skore/src/skore/item/pandas_series_item.py index bd606c35b..ff2f90a24 100644 --- a/skore/src/skore/item/pandas_series_item.py +++ b/skore/src/skore/item/pandas_series_item.py @@ -7,7 +7,7 @@ from __future__ import annotations from functools import cached_property -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from skore.item.item import Item, ItemTypeError @@ -29,9 +29,9 @@ def __init__( self, index_json: str, series_json: str, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a PandasSeriesItem. @@ -46,7 +46,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/polars_dataframe_item.py b/skore/src/skore/item/polars_dataframe_item.py index 6f2d0f26a..65141a4e5 100644 --- a/skore/src/skore/item/polars_dataframe_item.py +++ b/skore/src/skore/item/polars_dataframe_item.py @@ -7,7 +7,7 @@ from __future__ import annotations from functools import cached_property -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from skore.item.item import Item, ItemTypeError @@ -30,9 +30,9 @@ class PolarsDataFrameItem(Item): def __init__( self, dataframe_json: str, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a PolarsDataFrameItem. @@ -45,7 +45,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/polars_series_item.py b/skore/src/skore/item/polars_series_item.py index 7a63c8670..1bb0be6ef 100644 --- a/skore/src/skore/item/polars_series_item.py +++ b/skore/src/skore/item/polars_series_item.py @@ -7,7 +7,7 @@ from __future__ import annotations from functools import cached_property -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from skore.item.item import Item, ItemTypeError @@ -26,9 +26,9 @@ class PolarsSeriesItem(Item): def __init__( self, series_json: str, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a PolarsSeriesItem. @@ -41,7 +41,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/primitive_item.py b/skore/src/skore/item/primitive_item.py index 4ed71631d..e891e1e48 100644 --- a/skore/src/skore/item/primitive_item.py +++ b/skore/src/skore/item/primitive_item.py @@ -19,7 +19,7 @@ str, list["Primitive"], tuple["Primitive"], - dict[str | int | float, "Primitive"], + dict[Union[str, int, float], "Primitive"], ] @@ -48,9 +48,9 @@ class PrimitiveItem(Item): def __init__( self, primitive: Primitive, - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a PrimitiveItem. @@ -63,7 +63,7 @@ def __init__( The creation timestamp as ISO format. updated_at : str, optional The last update timestamp as ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note) diff --git a/skore/src/skore/item/sklearn_base_estimator_item.py b/skore/src/skore/item/sklearn_base_estimator_item.py index 40adce8d4..a842e807c 100644 --- a/skore/src/skore/item/sklearn_base_estimator_item.py +++ b/skore/src/skore/item/sklearn_base_estimator_item.py @@ -7,7 +7,7 @@ from __future__ import annotations from functools import cached_property -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from skore.item.item import Item, ItemTypeError @@ -28,9 +28,9 @@ def __init__( estimator_html_repr: str, estimator_skops: bytes, estimator_skops_untrusted_types: list[str], - created_at: str | None = None, - updated_at: str | None = None, - note: str | None = None, + created_at: Union[str, None] = None, + updated_at: Union[str, None] = None, + note: Union[str, None] = None, ): """ Initialize a SklearnBaseEstimatorItem. @@ -47,7 +47,7 @@ def __init__( The creation timestamp in ISO format. updated_at : str, optional The last update timestamp in ISO format. - note : str | None + note : Union[str, None] An optional note. """ super().__init__(created_at, updated_at, note)