diff --git a/pyproject.toml b/pyproject.toml index 381df0be..9de6847f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,6 @@ ignore = [ "PYI001", "PYI002", "PYI017", - "PYI019", # Request for more autofixes: https://github.com/astral-sh/ruff/issues/15798 "PYI024", "PYI048", "PYI051", # Request for autofix: https://github.com/astral-sh/ruff/issues/14185 diff --git a/stubs/sklearn/base.pyi b/stubs/sklearn/base.pyi index 6385a9ca..a2ab07f1 100644 --- a/stubs/sklearn/base.pyi +++ b/stubs/sklearn/base.pyi @@ -5,7 +5,8 @@ import re import warnings from collections import defaultdict as defaultdict from collections.abc import Iterable -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,8 +19,6 @@ from .utils._param_validation import validate_parameter_constraints as validate_ from .utils._set_output import _SetOutputMixin from .utils.validation import check_array as check_array, check_is_fitted as check_is_fitted, check_X_y as check_X_y -BaseEstimator_Self = TypeVar("BaseEstimator_Self", bound=BaseEstimator) - # Author: Gael Varoquaux # License: BSD 3 clause @@ -27,7 +26,7 @@ def clone(estimator: BaseEstimator | Iterable[BaseEstimator], *, safe: bool = Tr class BaseEstimator: def get_params(self, deep: bool = True) -> dict: ... - def set_params(self: BaseEstimator_Self, **params) -> BaseEstimator_Self: ... + def set_params(self, **params) -> Self: ... def __repr__(self, N_CHAR_MAX: int = 700) -> str: ... def __getstate__(self): ... def __setstate__(self, state) -> None: ... diff --git a/stubs/sklearn/calibration.pyi b/stubs/sklearn/calibration.pyi index 401dbd23..228ef563 100644 --- a/stubs/sklearn/calibration.pyi +++ b/stubs/sklearn/calibration.pyi @@ -4,7 +4,8 @@ from functools import partial as partial from inspect import signature as signature from math import log as log from numbers import Integral as Integral -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from matplotlib.artist import Artist @@ -33,9 +34,6 @@ from .utils.multiclass import check_classification_targets as check_classificati from .utils.parallel import Parallel as Parallel, delayed as delayed from .utils.validation import check_consistent_length as check_consistent_length, check_is_fitted as check_is_fitted -CalibratedClassifierCV_Self = TypeVar("CalibratedClassifierCV_Self", bound=CalibratedClassifierCV) -_SigmoidCalibration_Self = TypeVar("_SigmoidCalibration_Self", bound=_SigmoidCalibration) - class CalibratedClassifierCV(ClassifierMixin, MetaEstimatorMixin, BaseEstimator): calibrated_classifiers_: list = ... feature_names_in_: ndarray = ... @@ -55,12 +53,12 @@ class CalibratedClassifierCV(ClassifierMixin, MetaEstimatorMixin, BaseEstimator) base_estimator: str | BaseEstimator = "deprecated", ) -> None: ... def fit( - self: CalibratedClassifierCV_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None, **fit_params, - ) -> CalibratedClassifierCV_Self: ... + ) -> Self: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... def predict(self, X: MatrixLike) -> ndarray: ... @@ -80,11 +78,11 @@ class _SigmoidCalibration(RegressorMixin, BaseEstimator): a_: float = ... def fit( - self: _SigmoidCalibration_Self, + self, X: ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> _SigmoidCalibration_Self: ... + ) -> Self: ... def predict(self, T: ArrayLike) -> ndarray: ... def calibration_curve( diff --git a/stubs/sklearn/cluster/_affinity_propagation.pyi b/stubs/sklearn/cluster/_affinity_propagation.pyi index d13689e0..fd2cbb3e 100644 --- a/stubs/sklearn/cluster/_affinity_propagation.pyi +++ b/stubs/sklearn/cluster/_affinity_propagation.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -15,8 +16,6 @@ from ..utils import as_float_array as as_float_array, check_random_state as chec from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ..utils.validation import check_is_fitted as check_is_fitted -AffinityPropagation_Self = TypeVar("AffinityPropagation_Self", bound=AffinityPropagation) - ############################################################################### # Public API @@ -56,6 +55,6 @@ class AffinityPropagation(ClusterMixin, BaseEstimator): verbose: bool = False, random_state: RandomState | None | Int = None, ) -> None: ... - def fit(self: AffinityPropagation_Self, X: MatrixLike, y: Any = None) -> AffinityPropagation_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def fit_predict(self, X: MatrixLike, y: Any = None) -> ndarray: ... diff --git a/stubs/sklearn/cluster/_agglomerative.pyi b/stubs/sklearn/cluster/_agglomerative.pyi index ab0dcf95..f008bef0 100644 --- a/stubs/sklearn/cluster/_agglomerative.pyi +++ b/stubs/sklearn/cluster/_agglomerative.pyi @@ -1,7 +1,8 @@ import warnings from heapq import heapify as heapify, heappop as heappop, heappush as heappush, heappushpop as heappushpop from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import Memory @@ -21,9 +22,6 @@ from ..utils._param_validation import HasMethods as HasMethods, Hidden as Hidden from ..utils.validation import check_memory as check_memory from ._feature_agglomeration import AgglomerationTransform -FeatureAgglomeration_Self = TypeVar("FeatureAgglomeration_Self", bound=FeatureAgglomeration) -AgglomerativeClustering_Self = TypeVar("AgglomerativeClustering_Self", bound=AgglomerativeClustering) - ############################################################################### # Hierarchical tree building functions @@ -74,7 +72,7 @@ class AgglomerativeClustering(ClusterMixin, BaseEstimator): distance_threshold: None | Float = None, compute_distances: bool = False, ) -> None: ... - def fit(self: AgglomerativeClustering_Self, X: MatrixLike, y: Any = None) -> AgglomerativeClustering_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def fit_predict(self, X: MatrixLike, y: Any = None) -> ndarray: ... class FeatureAgglomeration(ClassNamePrefixFeaturesOutMixin, AgglomerativeClustering, AgglomerationTransform): @@ -103,5 +101,5 @@ class FeatureAgglomeration(ClassNamePrefixFeaturesOutMixin, AgglomerativeCluster distance_threshold: None | Float = None, compute_distances: bool = False, ) -> None: ... - def fit(self: FeatureAgglomeration_Self, X: MatrixLike, y: Any = None) -> FeatureAgglomeration_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def fit_predict(self): ... diff --git a/stubs/sklearn/cluster/_bicluster.pyi b/stubs/sklearn/cluster/_bicluster.pyi index bed6096f..7112a50a 100644 --- a/stubs/sklearn/cluster/_bicluster.pyi +++ b/stubs/sklearn/cluster/_bicluster.pyi @@ -1,6 +1,7 @@ from abc import ABCMeta, abstractmethod from numbers import Integral as Integral -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -21,8 +22,6 @@ from ..utils.extmath import ( from ..utils.validation import assert_all_finite as assert_all_finite from . import KMeans as KMeans, MiniBatchKMeans as MiniBatchKMeans -BaseSpectral_Self = TypeVar("BaseSpectral_Self", bound=BaseSpectral) - __all__ = ["SpectralCoclustering", "SpectralBiclustering"] class BaseSpectral(BiclusterMixin, BaseEstimator, metaclass=ABCMeta): @@ -39,7 +38,7 @@ class BaseSpectral(BiclusterMixin, BaseEstimator, metaclass=ABCMeta): n_init: int = 10, random_state: None | int = None, ) -> None: ... - def fit(self: BaseSpectral_Self, X: MatrixLike, y: Any = None) -> BaseSpectral_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... class SpectralCoclustering(BaseSpectral): feature_names_in_: ndarray = ... diff --git a/stubs/sklearn/cluster/_birch.pyi b/stubs/sklearn/cluster/_birch.pyi index 9e1801e9..32409a94 100644 --- a/stubs/sklearn/cluster/_birch.pyi +++ b/stubs/sklearn/cluster/_birch.pyi @@ -1,7 +1,8 @@ import warnings from math import sqrt as sqrt from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -19,8 +20,6 @@ from ..utils.extmath import row_norms as row_norms from ..utils.validation import check_is_fitted as check_is_fitted from . import AgglomerativeClustering as AgglomerativeClustering -Birch_Self = TypeVar("Birch_Self", bound=Birch) - # Authors: Manoj Kumar # Alexandre Gramfort # Joel Nothman @@ -86,7 +85,7 @@ class Birch(ClassNamePrefixFeaturesOutMixin, ClusterMixin, TransformerMixin, Bas compute_labels: bool = True, copy: bool = True, ) -> None: ... - def fit(self: Birch_Self, X: MatrixLike | ArrayLike, y: Any = None) -> Birch_Self: ... - def partial_fit(self: Birch_Self, X: None | MatrixLike | ArrayLike = None, y: Any = None) -> Birch_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... + def partial_fit(self, X: None | MatrixLike | ArrayLike = None, y: Any = None) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray | spmatrix: ... diff --git a/stubs/sklearn/cluster/_bisect_k_means.pyi b/stubs/sklearn/cluster/_bisect_k_means.pyi index f4dfd84a..685cccbc 100644 --- a/stubs/sklearn/cluster/_bisect_k_means.pyi +++ b/stubs/sklearn/cluster/_bisect_k_means.pyi @@ -1,6 +1,7 @@ import warnings from collections.abc import Iterator -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -13,8 +14,6 @@ from ..utils.extmath import row_norms as row_norms from ..utils.validation import check_is_fitted as check_is_fitted, check_random_state as check_random_state from ._kmeans import _BaseKMeans -BisectingKMeans_Self = TypeVar("BisectingKMeans_Self", bound=BisectingKMeans) - # Author: Michal Krawczyk class _BisectingTree: @@ -47,9 +46,9 @@ class BisectingKMeans(_BaseKMeans): bisecting_strategy: Literal["biggest_inertia", "largest_cluster"] = "biggest_inertia", ) -> None: ... def fit( - self: BisectingKMeans_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> BisectingKMeans_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/cluster/_dbscan.pyi b/stubs/sklearn/cluster/_dbscan.pyi index 5c43bb36..e8d5235b 100644 --- a/stubs/sklearn/cluster/_dbscan.pyi +++ b/stubs/sklearn/cluster/_dbscan.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -12,8 +13,6 @@ from ..neighbors import NearestNeighbors as NearestNeighbors from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ._dbscan_inner import dbscan_inner as dbscan_inner -DBSCAN_Self = TypeVar("DBSCAN_Self", bound=DBSCAN) - # Author: Robert Layton # Joel Nothman # Lars Buitinck @@ -56,9 +55,9 @@ class DBSCAN(ClusterMixin, BaseEstimator): n_jobs: None | Int = None, ) -> None: ... def fit( - self: DBSCAN_Self, + self, X: MatrixLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> DBSCAN_Self: ... + ) -> Self: ... def fit_predict(self, X: MatrixLike, y: Any = None, sample_weight: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/cluster/_kmeans.pyi b/stubs/sklearn/cluster/_kmeans.pyi index 3fcd8fec..6d1269ff 100644 --- a/stubs/sklearn/cluster/_kmeans.pyi +++ b/stubs/sklearn/cluster/_kmeans.pyi @@ -1,7 +1,8 @@ import warnings from abc import ABC, abstractmethod as abstractmethod from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -36,9 +37,6 @@ from ._k_means_lloyd import ( lloyd_iter_chunked_sparse as lloyd_iter_chunked_sparse, ) -KMeans_Self = TypeVar("KMeans_Self", bound=KMeans) -MiniBatchKMeans_Self = TypeVar("MiniBatchKMeans_Self", bound=MiniBatchKMeans) - ############################################################################### # Initialization heuristic @@ -125,11 +123,11 @@ class KMeans(_BaseKMeans): algorithm: Literal["lloyd", "elkan", "auto", "full"] = "lloyd", ) -> None: ... def fit( - self: KMeans_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> KMeans_Self: ... + ) -> Self: ... class MiniBatchKMeans(_BaseKMeans): feature_names_in_: ndarray = ... @@ -159,14 +157,14 @@ class MiniBatchKMeans(_BaseKMeans): reassignment_ratio: Float = 0.01, ) -> None: ... def fit( - self: MiniBatchKMeans_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> MiniBatchKMeans_Self: ... + ) -> Self: ... def partial_fit( - self: MiniBatchKMeans_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> MiniBatchKMeans_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/cluster/_mean_shift.pyi b/stubs/sklearn/cluster/_mean_shift.pyi index 2095530d..e26205f6 100644 --- a/stubs/sklearn/cluster/_mean_shift.pyi +++ b/stubs/sklearn/cluster/_mean_shift.pyi @@ -1,7 +1,8 @@ import warnings from collections import defaultdict as defaultdict from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -17,8 +18,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted -MeanShift_Self = TypeVar("MeanShift_Self", bound=MeanShift) - # Authors: Conrad Lee # Alexandre Gramfort # Gael Varoquaux @@ -65,5 +64,5 @@ class MeanShift(ClusterMixin, BaseEstimator): n_jobs: None | Int = None, max_iter: Int = 300, ) -> None: ... - def fit(self: MeanShift_Self, X: MatrixLike, y: Any = None) -> MeanShift_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/cluster/_optics.pyi b/stubs/sklearn/cluster/_optics.pyi index 0d3ab172..016c71c7 100644 --- a/stubs/sklearn/cluster/_optics.pyi +++ b/stubs/sklearn/cluster/_optics.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import Memory @@ -17,8 +18,6 @@ from ..utils import gen_batches as gen_batches, get_chunk_n_rows as get_chunk_n_ from ..utils._param_validation import HasMethods as HasMethods, Interval as Interval, StrOptions as StrOptions from ..utils.validation import check_memory as check_memory -OPTICS_Self = TypeVar("OPTICS_Self", bound=OPTICS) - class OPTICS(ClusterMixin, BaseEstimator): feature_names_in_: ndarray = ... n_features_in_: int = ... @@ -49,7 +48,7 @@ class OPTICS(ClusterMixin, BaseEstimator): memory: None | Memory | str = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: OPTICS_Self, X: MatrixLike, y: Any = None) -> OPTICS_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def compute_optics_graph( X: MatrixLike, diff --git a/stubs/sklearn/cluster/_spectral.pyi b/stubs/sklearn/cluster/_spectral.pyi index d36191c6..8602aa1b 100644 --- a/stubs/sklearn/cluster/_spectral.pyi +++ b/stubs/sklearn/cluster/_spectral.pyi @@ -1,7 +1,8 @@ import warnings from collections.abc import Mapping from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -19,8 +20,6 @@ from ..utils import as_float_array as as_float_array, check_random_state as chec from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ._kmeans import k_means as k_means -SpectralClustering_Self = TypeVar("SpectralClustering_Self", bound=SpectralClustering) - def cluster_qr(vectors: MatrixLike) -> ndarray: ... def discretize( vectors: MatrixLike, @@ -70,5 +69,5 @@ class SpectralClustering(ClusterMixin, BaseEstimator): n_jobs: None | Int = None, verbose: bool = False, ) -> None: ... - def fit(self: SpectralClustering_Self, X: MatrixLike, y: Any = None) -> SpectralClustering_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def fit_predict(self, X: MatrixLike, y: Any = None) -> ndarray: ... diff --git a/stubs/sklearn/compose/_column_transformer.pyi b/stubs/sklearn/compose/_column_transformer.pyi index 73d8c6c8..fd292dac 100644 --- a/stubs/sklearn/compose/_column_transformer.pyi +++ b/stubs/sklearn/compose/_column_transformer.pyi @@ -1,7 +1,8 @@ from collections import Counter as Counter from collections.abc import Sequence from itertools import chain as chain -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import dtype, ndarray @@ -17,8 +18,6 @@ from ..utils.metaestimators import _BaseComposition from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_array as check_array, check_is_fitted as check_is_fitted -ColumnTransformer_Self = TypeVar("ColumnTransformer_Self", bound=ColumnTransformer) - __all__ = ["ColumnTransformer", "make_column_transformer", "make_column_selector"] _ERR_MSG_1DCOLUMN: str = ... @@ -44,11 +43,11 @@ class ColumnTransformer(TransformerMixin, _BaseComposition): ) -> None: ... def set_output(self, *, transform: None | Literal["default", "pandas"] = None) -> BaseEstimator: ... def get_params(self, deep: bool = True) -> dict: ... - def set_params(self: ColumnTransformer_Self, **kwargs) -> ColumnTransformer_Self: ... + def set_params(self, **kwargs) -> Self: ... @property def named_transformers_(self) -> Bunch: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... - def fit(self: ColumnTransformer_Self, X: MatrixLike, y: None | ArrayLike = None) -> ColumnTransformer_Self: ... + def fit(self, X: MatrixLike, y: None | ArrayLike = None) -> Self: ... def fit_transform(self, X: MatrixLike, y: None | ArrayLike = None) -> ndarray | spmatrix: ... def transform(self, X: MatrixLike) -> ndarray | spmatrix: ... diff --git a/stubs/sklearn/compose/_target.pyi b/stubs/sklearn/compose/_target.pyi index fae67d6c..b890ac9f 100644 --- a/stubs/sklearn/compose/_target.pyi +++ b/stubs/sklearn/compose/_target.pyi @@ -1,5 +1,6 @@ import warnings -from typing import Any, Callable, ClassVar, TypeVar +from typing import Any, Callable, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -13,8 +14,6 @@ from ..utils import check_array as check_array from ..utils._param_validation import HasMethods as HasMethods from ..utils.validation import check_is_fitted as check_is_fitted -TransformedTargetRegressor_Self = TypeVar("TransformedTargetRegressor_Self", bound=TransformedTargetRegressor) - # Authors: Andreas Mueller # Guillaume Lemaitre # License: BSD 3 clause @@ -38,11 +37,11 @@ class TransformedTargetRegressor(RegressorMixin, BaseEstimator): check_inverse: bool = True, ) -> None: ... def fit( - self: TransformedTargetRegressor_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, **fit_params, - ) -> TransformedTargetRegressor_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike, **predict_params) -> ndarray: ... @property def n_features_in_(self) -> int: ... diff --git a/stubs/sklearn/covariance/_elliptic_envelope.pyi b/stubs/sklearn/covariance/_elliptic_envelope.pyi index d8f71373..b772c19a 100644 --- a/stubs/sklearn/covariance/_elliptic_envelope.pyi +++ b/stubs/sklearn/covariance/_elliptic_envelope.pyi @@ -1,5 +1,6 @@ from numbers import Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -12,8 +13,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.validation import check_is_fitted as check_is_fitted from . import MinCovDet -EllipticEnvelope_Self = TypeVar("EllipticEnvelope_Self", bound=EllipticEnvelope) - # Author: Virgile Fritsch # # License: BSD 3 clause @@ -42,7 +41,7 @@ class EllipticEnvelope(OutlierMixin, MinCovDet): contamination: Float = 0.1, random_state: RandomState | None | Int = None, ) -> None: ... - def fit(self: EllipticEnvelope_Self, X: MatrixLike, y: Any = None) -> EllipticEnvelope_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def decision_function(self, X: MatrixLike) -> ndarray: ... def score_samples(self, X: MatrixLike) -> ArrayLike: ... def predict(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/covariance/_empirical_covariance.pyi b/stubs/sklearn/covariance/_empirical_covariance.pyi index f7bee504..a0348b26 100644 --- a/stubs/sklearn/covariance/_empirical_covariance.pyi +++ b/stubs/sklearn/covariance/_empirical_covariance.pyi @@ -1,5 +1,6 @@ import warnings -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -12,8 +13,6 @@ from ..metrics.pairwise import pairwise_distances as pairwise_distances from ..utils import check_array as check_array from ..utils.extmath import fast_logdet as fast_logdet -EmpiricalCovariance_Self = TypeVar("EmpiricalCovariance_Self", bound=EmpiricalCovariance) - # Author: Alexandre Gramfort # Gael Varoquaux # Virgile Fritsch @@ -36,7 +35,7 @@ class EmpiricalCovariance(BaseEstimator): def __init__(self, *, store_precision: bool = True, assume_centered: bool = False) -> None: ... def get_precision(self) -> ndarray: ... - def fit(self: EmpiricalCovariance_Self, X: MatrixLike, y: Any = None) -> EmpiricalCovariance_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def score(self, X_test: MatrixLike, y: Any = None) -> Float: ... def error_norm( self, diff --git a/stubs/sklearn/covariance/_graph_lasso.pyi b/stubs/sklearn/covariance/_graph_lasso.pyi index 2d622059..90fa792e 100644 --- a/stubs/sklearn/covariance/_graph_lasso.pyi +++ b/stubs/sklearn/covariance/_graph_lasso.pyi @@ -4,7 +4,8 @@ import time import warnings from collections.abc import Iterable from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -19,9 +20,6 @@ from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_random_state as check_random_state, check_scalar as check_scalar from . import EmpiricalCovariance, empirical_covariance as empirical_covariance, log_likelihood as log_likelihood -GraphicalLassoCV_Self = TypeVar("GraphicalLassoCV_Self", bound=GraphicalLassoCV) -GraphicalLasso_Self = TypeVar("GraphicalLasso_Self", bound=GraphicalLasso) - # Author: Gael Varoquaux # License: BSD 3 clause # Copyright: INRIA @@ -83,7 +81,7 @@ class GraphicalLasso(BaseGraphicalLasso): verbose: bool = False, assume_centered: bool = False, ) -> None: ... - def fit(self: GraphicalLasso_Self, X: MatrixLike, y: Any = None) -> GraphicalLasso_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... # Cross-validation with GraphicalLasso def graphical_lasso_path( @@ -124,4 +122,4 @@ class GraphicalLassoCV(BaseGraphicalLasso): verbose: bool = False, assume_centered: bool = False, ) -> None: ... - def fit(self: GraphicalLassoCV_Self, X: MatrixLike, y: Any = None) -> GraphicalLassoCV_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... diff --git a/stubs/sklearn/covariance/_robust_covariance.pyi b/stubs/sklearn/covariance/_robust_covariance.pyi index e31b78ca..bc7e4211 100644 --- a/stubs/sklearn/covariance/_robust_covariance.pyi +++ b/stubs/sklearn/covariance/_robust_covariance.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, TypeVar +from typing import Any, Callable, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,8 +15,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.extmath import fast_logdet as fast_logdet from . import EmpiricalCovariance, empirical_covariance as empirical_covariance -MinCovDet_Self = TypeVar("MinCovDet_Self", bound=MinCovDet) - # Author: Virgile Fritsch # # License: BSD 3 clause @@ -76,6 +75,6 @@ class MinCovDet(EmpiricalCovariance): support_fraction: None | Float = None, random_state: RandomState | None | Int = None, ) -> None: ... - def fit(self: MinCovDet_Self, X: MatrixLike, y: Any = None) -> MinCovDet_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def correct_covariance(self, data: MatrixLike) -> ndarray: ... def reweight_covariance(self, data: MatrixLike) -> tuple[ndarray, ndarray, ndarray]: ... diff --git a/stubs/sklearn/covariance/_shrunk_covariance.pyi b/stubs/sklearn/covariance/_shrunk_covariance.pyi index d2a0a961..1aa032af 100644 --- a/stubs/sklearn/covariance/_shrunk_covariance.pyi +++ b/stubs/sklearn/covariance/_shrunk_covariance.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -11,10 +12,6 @@ from ..utils import check_array as check_array from ..utils._param_validation import Interval as Interval from . import EmpiricalCovariance, empirical_covariance as empirical_covariance -ShrunkCovariance_Self = TypeVar("ShrunkCovariance_Self", bound=ShrunkCovariance) -LedoitWolf_Self = TypeVar("LedoitWolf_Self", bound=LedoitWolf) -OAS_Self = TypeVar("OAS_Self", bound=OAS) - # Author: Alexandre Gramfort # Gael Varoquaux # Virgile Fritsch @@ -37,7 +34,7 @@ class ShrunkCovariance(EmpiricalCovariance): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, store_precision: bool = True, assume_centered: bool = False, shrinkage: Float = 0.1) -> None: ... - def fit(self: ShrunkCovariance_Self, X: MatrixLike, y: Any = None) -> ShrunkCovariance_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... # Ledoit-Wolf estimator @@ -57,7 +54,7 @@ class LedoitWolf(EmpiricalCovariance): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, store_precision: bool = True, assume_centered: bool = False, block_size: Int = 1000) -> None: ... - def fit(self: LedoitWolf_Self, X: MatrixLike, y: Any = None) -> LedoitWolf_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... # OAS estimator def oas(X: MatrixLike, *, assume_centered: bool = False) -> tuple[ndarray, Float] | tuple[ndarray, float]: ... @@ -70,4 +67,4 @@ class OAS(EmpiricalCovariance): location_: ndarray = ... covariance_: ndarray = ... - def fit(self: OAS_Self, X: MatrixLike, y: Any = None) -> OAS_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... diff --git a/stubs/sklearn/cross_decomposition/_pls.pyi b/stubs/sklearn/cross_decomposition/_pls.pyi index 97212d78..0c7da261 100644 --- a/stubs/sklearn/cross_decomposition/_pls.pyi +++ b/stubs/sklearn/cross_decomposition/_pls.pyi @@ -1,7 +1,8 @@ import warnings from abc import ABCMeta, abstractmethod from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,10 +15,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.extmath import svd_flip as svd_flip from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted -PLSSVD_Self = TypeVar("PLSSVD_Self", bound=PLSSVD) -PLSRegression_Self = TypeVar("PLSRegression_Self", bound=PLSRegression) -_PLS_Self = TypeVar("_PLS_Self", bound=_PLS) - __all__ = ["PLSCanonical", "PLSRegression", "PLSSVD"] class _PLS( @@ -43,7 +40,7 @@ class _PLS( tol: float = 1e-06, copy: bool = True, ) -> None: ... - def fit(self: _PLS_Self, X: MatrixLike, Y: MatrixLike | ArrayLike) -> _PLS_Self: ... + def fit(self, X: MatrixLike, Y: MatrixLike | ArrayLike) -> Self: ... def transform( self, X: MatrixLike, Y: None | MatrixLike = None, copy: bool = True ) -> tuple[ndarray, ...] | ndarray | tuple[ndarray, ndarray]: ... @@ -84,7 +81,7 @@ class PLSRegression(_PLS): tol: Float = 1e-06, copy: bool = True, ) -> None: ... - def fit(self: PLSRegression_Self, X: MatrixLike, Y: MatrixLike | ArrayLike) -> PLSRegression_Self: ... + def fit(self, X: MatrixLike, Y: MatrixLike | ArrayLike) -> Self: ... class PLSCanonical(_PLS): feature_names_in_: ndarray = ... @@ -154,6 +151,6 @@ class PLSSVD(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, n_components: Int = 2, *, scale: bool = True, copy: bool = True) -> None: ... - def fit(self: PLSSVD_Self, X: MatrixLike, Y: MatrixLike | ArrayLike) -> PLSSVD_Self: ... + def fit(self, X: MatrixLike, Y: MatrixLike | ArrayLike) -> Self: ... def transform(self, X: MatrixLike, Y: None | MatrixLike | ArrayLike = None) -> ndarray | tuple[ndarray, ndarray]: ... def fit_transform(self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None) -> ndarray | tuple[ndarray, ndarray]: ... diff --git a/stubs/sklearn/decomposition/_base.pyi b/stubs/sklearn/decomposition/_base.pyi index df6e38c0..5599b75d 100644 --- a/stubs/sklearn/decomposition/_base.pyi +++ b/stubs/sklearn/decomposition/_base.pyi @@ -1,5 +1,5 @@ from abc import ABCMeta, abstractmethod -from typing import TypeVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -9,8 +9,6 @@ from .._typing import MatrixLike from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin from ..utils.validation import check_is_fitted as check_is_fitted -_BasePCA_Self = TypeVar("_BasePCA_Self", bound=_BasePCA) - # Author: Alexandre Gramfort # Olivier Grisel # Mathieu Blondel @@ -23,6 +21,6 @@ class _BasePCA(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator, def get_covariance(self) -> ndarray: ... def get_precision(self) -> ndarray: ... @abstractmethod - def fit(self: _BasePCA_Self, X: MatrixLike, y=None) -> _BasePCA_Self: ... + def fit(self, X: MatrixLike, y=None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/decomposition/_dict_learning.pyi b/stubs/sklearn/decomposition/_dict_learning.pyi index 4e94948a..e95156cc 100644 --- a/stubs/sklearn/decomposition/_dict_learning.pyi +++ b/stubs/sklearn/decomposition/_dict_learning.pyi @@ -4,7 +4,8 @@ import time import warnings from math import ceil as ceil from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import effective_n_jobs as effective_n_jobs @@ -27,10 +28,6 @@ from ..utils.extmath import randomized_svd as randomized_svd, row_norms as row_n from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted -DictionaryLearning_Self = TypeVar("DictionaryLearning_Self", bound=DictionaryLearning) -SparseCoder_Self = TypeVar("SparseCoder_Self", bound=SparseCoder) -MiniBatchDictionaryLearning_Self = TypeVar("MiniBatchDictionaryLearning_Self", bound=MiniBatchDictionaryLearning) - # Author: Vlad Niculae, Gael Varoquaux, Alexandre Gramfort # License: BSD 3 clause @@ -128,7 +125,7 @@ class SparseCoder(_BaseSparseCoding, BaseEstimator): positive_code: bool = False, transform_max_iter: Int = 1000, ) -> None: ... - def fit(self: SparseCoder_Self, X: Any, y: Any = None) -> SparseCoder_Self: ... + def fit(self, X: Any, y: Any = None) -> Self: ... def transform(self, X: ArrayLike, y: Any = None) -> ndarray: ... @property def n_components_(self) -> int: ... @@ -165,7 +162,7 @@ class DictionaryLearning(_BaseSparseCoding, BaseEstimator): positive_dict: bool = False, transform_max_iter: Int = 1000, ) -> None: ... - def fit(self: DictionaryLearning_Self, X: MatrixLike, y: Any = None) -> DictionaryLearning_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator): n_steps_: int = ... @@ -210,10 +207,10 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator): @deprecated("The attribute `inner_stats_` is deprecated in 1.1 and will be removed in 1.3.") # type: ignore @property def inner_stats_(self) -> tuple[ndarray, ndarray]: ... - def fit(self: MiniBatchDictionaryLearning_Self, X: MatrixLike, y: Any = None) -> MiniBatchDictionaryLearning_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def partial_fit( - self: MiniBatchDictionaryLearning_Self, + self, X: MatrixLike, y: Any = None, iter_offset: str | Int = "deprecated", - ) -> MiniBatchDictionaryLearning_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/decomposition/_factor_analysis.pyi b/stubs/sklearn/decomposition/_factor_analysis.pyi index 2c271c6b..1e8b3f70 100644 --- a/stubs/sklearn/decomposition/_factor_analysis.pyi +++ b/stubs/sklearn/decomposition/_factor_analysis.pyi @@ -1,7 +1,8 @@ import warnings from math import log as log, sqrt as sqrt from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -16,8 +17,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.extmath import fast_logdet as fast_logdet, randomized_svd as randomized_svd, squared_norm as squared_norm from ..utils.validation import check_is_fitted as check_is_fitted -FactorAnalysis_Self = TypeVar("FactorAnalysis_Self", bound=FactorAnalysis) - # Author: Christian Osendorfer # Alexandre Gramfort # Denis A. Engemann @@ -48,7 +47,7 @@ class FactorAnalysis(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEsti rotation: None | Literal["varimax", "quartimax"] = None, random_state: None | RandomState | int = 0, ) -> None: ... - def fit(self: FactorAnalysis_Self, X: MatrixLike, y: Any = None) -> FactorAnalysis_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... def get_covariance(self) -> ndarray: ... def get_precision(self) -> ndarray: ... diff --git a/stubs/sklearn/decomposition/_fastica.pyi b/stubs/sklearn/decomposition/_fastica.pyi index de356873..02210b28 100644 --- a/stubs/sklearn/decomposition/_fastica.pyi +++ b/stubs/sklearn/decomposition/_fastica.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,8 +15,6 @@ from ..utils import as_float_array as as_float_array, check_array as check_array from ..utils._param_validation import Hidden as Hidden, Interval as Interval, StrOptions as StrOptions from ..utils.validation import check_is_fitted as check_is_fitted -FastICA_Self = TypeVar("FastICA_Self", bound=FastICA) - # Authors: Pierre Lafaye de Micheaux, Stefan van der Walt, Gael Varoquaux, # Bertrand Thirion, Alexandre Gramfort, Denis A. Engemann # License: BSD 3 clause @@ -66,6 +65,6 @@ class FastICA(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): random_state: RandomState | None | Int = None, ) -> None: ... def fit_transform(self, X: MatrixLike, y: Any = None) -> ndarray: ... - def fit(self: FastICA_Self, X: MatrixLike, y: Any = None) -> FastICA_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike, copy: bool = True) -> ndarray: ... def inverse_transform(self, X: MatrixLike, copy: bool = True) -> ndarray: ... diff --git a/stubs/sklearn/decomposition/_incremental_pca.pyi b/stubs/sklearn/decomposition/_incremental_pca.pyi index a9dd9e10..4fec369d 100644 --- a/stubs/sklearn/decomposition/_incremental_pca.pyi +++ b/stubs/sklearn/decomposition/_incremental_pca.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -11,8 +12,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.extmath import svd_flip as svd_flip from ._base import _BasePCA -IncrementalPCA_Self = TypeVar("IncrementalPCA_Self", bound=IncrementalPCA) - class IncrementalPCA(_BasePCA): feature_names_in_: ndarray = ... n_features_in_: int = ... @@ -32,11 +31,11 @@ class IncrementalPCA(_BasePCA): def __init__( self, n_components: None | Int = None, *, whiten: bool = False, copy: bool = True, batch_size: None | Int = None ) -> None: ... - def fit(self: IncrementalPCA_Self, X: MatrixLike | ArrayLike, y: Any = None) -> IncrementalPCA_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def partial_fit( - self: IncrementalPCA_Self, + self, X: MatrixLike, y: Any = None, check_input: bool = True, - ) -> IncrementalPCA_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/decomposition/_kernel_pca.pyi b/stubs/sklearn/decomposition/_kernel_pca.pyi index 6ff5435c..00b09f38 100644 --- a/stubs/sklearn/decomposition/_kernel_pca.pyi +++ b/stubs/sklearn/decomposition/_kernel_pca.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -16,8 +17,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.extmath import svd_flip as svd_flip from ..utils.validation import check_is_fitted as check_is_fitted -KernelPCA_Self = TypeVar("KernelPCA_Self", bound=KernelPCA) - # Author: Mathieu Blondel # Sylvain Marie # License: BSD 3 clause @@ -53,7 +52,7 @@ class KernelPCA(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator copy_X: bool = True, n_jobs: None | Int = None, ) -> None: ... - def fit(self: KernelPCA_Self, X: MatrixLike | ArrayLike, y: Any = None) -> KernelPCA_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def fit_transform(self, X: MatrixLike | ArrayLike, y: Any = None, **params) -> ndarray: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/decomposition/_lda.pyi b/stubs/sklearn/decomposition/_lda.pyi index 957aa8be..dce7435a 100644 --- a/stubs/sklearn/decomposition/_lda.pyi +++ b/stubs/sklearn/decomposition/_lda.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -16,8 +17,6 @@ from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted, check_non_negative as check_non_negative from ._online_lda_fast import mean_change as cy_mean_change -LatentDirichletAllocation_Self = TypeVar("LatentDirichletAllocation_Self", bound=LatentDirichletAllocation) - EPS = ... class LatentDirichletAllocation(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): @@ -54,10 +53,8 @@ class LatentDirichletAllocation(ClassNamePrefixFeaturesOutMixin, TransformerMixi verbose: Int = 0, random_state: RandomState | None | Int = None, ) -> None: ... - def partial_fit( - self: LatentDirichletAllocation_Self, X: MatrixLike | ArrayLike, y: Any = None - ) -> LatentDirichletAllocation_Self: ... - def fit(self: LatentDirichletAllocation_Self, X: MatrixLike | ArrayLike, y: Any = None) -> LatentDirichletAllocation_Self: ... + def partial_fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... def score(self, X: MatrixLike | ArrayLike, y: Any = None) -> float: ... def perplexity(self, X: MatrixLike | ArrayLike, sub_sampling: bool = False) -> float: ... diff --git a/stubs/sklearn/decomposition/_nmf.pyi b/stubs/sklearn/decomposition/_nmf.pyi index 24569c2f..38a5e095 100644 --- a/stubs/sklearn/decomposition/_nmf.pyi +++ b/stubs/sklearn/decomposition/_nmf.pyi @@ -4,7 +4,8 @@ import warnings from abc import ABC from math import sqrt as sqrt from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -22,9 +23,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.extmath import randomized_svd as randomized_svd, safe_sparse_dot as safe_sparse_dot, squared_norm as squared_norm from ..utils.validation import check_is_fitted as check_is_fitted, check_non_negative as check_non_negative -MiniBatchNMF_Self = TypeVar("MiniBatchNMF_Self", bound=MiniBatchNMF) -_BaseNMF_Self = TypeVar("_BaseNMF_Self", bound=_BaseNMF) - EPSILON = ... def norm(x: ArrayLike) -> float: ... @@ -66,7 +64,7 @@ class _BaseNMF(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator, l1_ratio: float = 0.0, verbose: int = 0, ) -> None: ... - def fit(self: _BaseNMF_Self, X: MatrixLike | ArrayLike, y: Any = None, **params) -> _BaseNMF_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None, **params) -> Self: ... def inverse_transform(self, W: MatrixLike) -> ndarray | spmatrix: ... class NMF(_BaseNMF): @@ -144,9 +142,9 @@ class MiniBatchNMF(_BaseNMF): ) -> ndarray: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... def partial_fit( - self: MiniBatchNMF_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, W: None | MatrixLike = None, H: None | ArrayLike = None, - ) -> MiniBatchNMF_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/decomposition/_pca.pyi b/stubs/sklearn/decomposition/_pca.pyi index 77a04534..08f823ab 100644 --- a/stubs/sklearn/decomposition/_pca.pyi +++ b/stubs/sklearn/decomposition/_pca.pyi @@ -1,6 +1,7 @@ from math import log as log, sqrt as sqrt from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -23,8 +24,6 @@ from ..utils.extmath import ( from ..utils.validation import check_is_fitted as check_is_fitted from ._base import _BasePCA -PCA_Self = TypeVar("PCA_Self", bound=PCA) - class PCA(_BasePCA): feature_names_in_: ndarray = ... n_features_in_: int = ... @@ -60,7 +59,7 @@ class PCA(_BasePCA): ) @property def n_features_(self) -> int: ... - def fit(self: PCA_Self, X: MatrixLike, y: Any = None) -> PCA_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def fit_transform(self, X: MatrixLike, y: Any = None) -> ndarray: ... def score_samples(self, X: MatrixLike) -> ndarray: ... def score(self, X: MatrixLike, y: Any = None) -> float: ... diff --git a/stubs/sklearn/decomposition/_sparse_pca.pyi b/stubs/sklearn/decomposition/_sparse_pca.pyi index 6ec58496..ac45a073 100644 --- a/stubs/sklearn/decomposition/_sparse_pca.pyi +++ b/stubs/sklearn/decomposition/_sparse_pca.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,8 +15,6 @@ from ..utils.extmath import svd_flip as svd_flip from ..utils.validation import check_array as check_array, check_is_fitted as check_is_fitted from ._dict_learning import MiniBatchDictionaryLearning as MiniBatchDictionaryLearning, dict_learning as dict_learning -_BaseSparsePCA_Self = TypeVar("_BaseSparsePCA_Self", bound=_BaseSparsePCA) - class _BaseSparsePCA(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... @@ -32,7 +31,7 @@ class _BaseSparsePCA(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEsti verbose: bool = False, random_state=None, ) -> None: ... - def fit(self: _BaseSparsePCA_Self, X: MatrixLike, y: Any = None) -> _BaseSparsePCA_Self | MiniBatchSparsePCA: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self | MiniBatchSparsePCA: ... def transform(self, X: ArrayLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/decomposition/_truncated_svd.pyi b/stubs/sklearn/decomposition/_truncated_svd.pyi index 71da6568..8b291add 100644 --- a/stubs/sklearn/decomposition/_truncated_svd.pyi +++ b/stubs/sklearn/decomposition/_truncated_svd.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -15,8 +16,6 @@ from ..utils.extmath import randomized_svd as randomized_svd, safe_sparse_dot as from ..utils.sparsefuncs import mean_variance_axis as mean_variance_axis from ..utils.validation import check_is_fitted as check_is_fitted -TruncatedSVD_Self = TypeVar("TruncatedSVD_Self", bound=TruncatedSVD) - __all__ = ["TruncatedSVD"] class TruncatedSVD(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): @@ -40,7 +39,7 @@ class TruncatedSVD(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstima random_state: RandomState | None | Int = None, tol: Float = 0.0, ) -> None: ... - def fit(self: TruncatedSVD_Self, X: MatrixLike | ArrayLike, y: Any = None) -> TruncatedSVD_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def fit_transform(self, X: MatrixLike | ArrayLike, y: Any = None) -> ndarray: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/discriminant_analysis.pyi b/stubs/sklearn/discriminant_analysis.pyi index 0a25b0c5..58666543 100644 --- a/stubs/sklearn/discriminant_analysis.pyi +++ b/stubs/sklearn/discriminant_analysis.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.linalg @@ -23,9 +24,6 @@ from .utils.extmath import softmax as softmax from .utils.multiclass import check_classification_targets as check_classification_targets, unique_labels as unique_labels from .utils.validation import check_is_fitted as check_is_fitted -LinearDiscriminantAnalysis_Self = TypeVar("LinearDiscriminantAnalysis_Self", bound=LinearDiscriminantAnalysis) -QuadraticDiscriminantAnalysis_Self = TypeVar("QuadraticDiscriminantAnalysis_Self", bound=QuadraticDiscriminantAnalysis) - # Authors: Clemens Brunner # Martin Billinger # Matthieu Perrot @@ -65,7 +63,7 @@ class LinearDiscriminantAnalysis( tol: Float = 1e-4, covariance_estimator: None | BaseEstimator | OAS = None, ) -> None: ... - def fit(self: LinearDiscriminantAnalysis_Self, X: MatrixLike, y: ArrayLike) -> LinearDiscriminantAnalysis_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... def predict_log_proba(self, X: MatrixLike) -> ndarray: ... @@ -86,7 +84,7 @@ class QuadraticDiscriminantAnalysis(ClassifierMixin, BaseEstimator): def __init__( self, *, priors: None | ArrayLike = None, reg_param: Float = 0.0, store_covariance: bool = False, tol: Float = 1.0e-4 ) -> None: ... - def fit(self: QuadraticDiscriminantAnalysis_Self, X: MatrixLike, y: ArrayLike) -> QuadraticDiscriminantAnalysis_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... def decision_function(self, X: MatrixLike) -> ndarray: ... def predict(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/dummy.pyi b/stubs/sklearn/dummy.pyi index bd286108..8bd94b04 100644 --- a/stubs/sklearn/dummy.pyi +++ b/stubs/sklearn/dummy.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -18,9 +19,6 @@ from .utils.validation import ( check_is_fitted as check_is_fitted, ) -DummyRegressor_Self = TypeVar("DummyRegressor_Self", bound=DummyRegressor) -DummyClassifier_Self = TypeVar("DummyClassifier_Self", bound=DummyClassifier) - # Author: Mathieu Blondel # Arnaud Joly # Maheshakya Wijewardena @@ -43,11 +41,11 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator): constant: None | str | ArrayLike | int = None, ) -> None: ... def fit( - self: DummyClassifier_Self, + self, X: MatrixLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> DummyClassifier_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray | list[ndarray]: ... def predict_log_proba(self, X: ArrayLike) -> ndarray | list[ndarray]: ... @@ -72,11 +70,11 @@ class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator): quantile: float | None = None, ) -> None: ... def fit( - self: DummyRegressor_Self, + self, X: MatrixLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> DummyRegressor_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike, return_std: bool = False) -> ndarray | tuple[ndarray, ndarray]: ... def score( self, diff --git a/stubs/sklearn/ensemble/_bagging.pyi b/stubs/sklearn/ensemble/_bagging.pyi index 1acad171..3a0eac59 100644 --- a/stubs/sklearn/ensemble/_bagging.pyi +++ b/stubs/sklearn/ensemble/_bagging.pyi @@ -3,7 +3,8 @@ import numbers from abc import ABCMeta, abstractmethod from functools import partial as partial from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self from warnings import warn as warn import numpy as np @@ -23,8 +24,6 @@ from ..utils.random import sample_without_replacement as sample_without_replacem from ..utils.validation import check_is_fitted as check_is_fitted, has_fit_parameter as has_fit_parameter from ._base import BaseEnsemble -BaseBagging_Self = TypeVar("BaseBagging_Self", bound=BaseBagging) - # Author: Gilles Louppe # License: BSD 3 clause @@ -53,11 +52,11 @@ class BaseBagging(BaseEnsemble, metaclass=ABCMeta): base_estimator: str = "deprecated", ) -> None: ... def fit( - self: BaseBagging_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BaggingRegressor | BaseBagging_Self: ... + ) -> BaggingRegressor | Self: ... def estimators_samples_(self): ... class BaggingClassifier(ClassifierMixin, BaseBagging): diff --git a/stubs/sklearn/ensemble/_forest.pyi b/stubs/sklearn/ensemble/_forest.pyi index a704f454..d0762743 100644 --- a/stubs/sklearn/ensemble/_forest.pyi +++ b/stubs/sklearn/ensemble/_forest.pyi @@ -2,7 +2,8 @@ import threading from abc import ABCMeta, abstractmethod from collections.abc import Mapping, Sequence from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self from warnings import catch_warnings as catch_warnings, simplefilter as simplefilter, warn as warn import numpy as np @@ -30,9 +31,6 @@ from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted from ._base import BaseEnsemble -BaseForest_Self = TypeVar("BaseForest_Self", bound=BaseForest) -RandomTreesEmbedding_Self = TypeVar("RandomTreesEmbedding_Self", bound=RandomTreesEmbedding) - __all__ = [ "RandomForestClassifier", "RandomForestRegressor", @@ -66,11 +64,11 @@ class BaseForest(MultiOutputMixin, BaseEnsemble, metaclass=ABCMeta): def apply(self, X: MatrixLike | ArrayLike) -> ndarray: ... def decision_path(self, X: MatrixLike | ArrayLike) -> tuple[spmatrix, ndarray]: ... def fit( - self: BaseForest_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BaseForest_Self: ... + ) -> Self: ... @property def feature_importances_(self) -> ndarray: ... @@ -293,11 +291,11 @@ class RandomTreesEmbedding(TransformerMixin, BaseForest): warm_start: bool = False, ) -> None: ... def fit( - self: RandomTreesEmbedding_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> RandomTreesEmbedding_Self: ... + ) -> Self: ... def fit_transform( self, X: MatrixLike | ArrayLike, diff --git a/stubs/sklearn/ensemble/_gb.pyi b/stubs/sklearn/ensemble/_gb.pyi index 9f9cd667..4bd83636 100644 --- a/stubs/sklearn/ensemble/_gb.pyi +++ b/stubs/sklearn/ensemble/_gb.pyi @@ -3,7 +3,8 @@ from abc import ABCMeta, abstractmethod from collections.abc import Iterator from numbers import Integral as Integral, Real as Real from time import time as time -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -24,8 +25,6 @@ from ._base import BaseEnsemble from ._gb_losses import LossFunction from ._gradient_boosting import predict_stage as predict_stage, predict_stages as predict_stages -BaseGradientBoosting_Self = TypeVar("BaseGradientBoosting_Self", bound=BaseGradientBoosting) - class VerboseReporter: def __init__(self, verbose: Int) -> None: ... def init(self, est: BaseEstimator, begin_at_stage: Int = 0): ... @@ -61,12 +60,12 @@ class BaseGradientBoosting(BaseEnsemble, metaclass=ABCMeta): tol: float = 1e-4, ) -> None: ... def fit( - self: BaseGradientBoosting_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, monitor: None | Callable = None, - ) -> BaseGradientBoosting_Self: ... + ) -> Self: ... @property def feature_importances_(self) -> ndarray: ... def apply(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/ensemble/_hist_gradient_boosting/binning.pyi b/stubs/sklearn/ensemble/_hist_gradient_boosting/binning.pyi index 519d2567..7bd77b07 100644 --- a/stubs/sklearn/ensemble/_hist_gradient_boosting/binning.pyi +++ b/stubs/sklearn/ensemble/_hist_gradient_boosting/binning.pyi @@ -1,5 +1,5 @@ from collections.abc import Sequence -from typing import TypeVar +from typing_extensions import Self import numpy as np from numpy import ndarray, uint8 @@ -18,8 +18,6 @@ from .common import ( X_DTYPE as X_DTYPE, ) -_BinMapper_Self = TypeVar("_BinMapper_Self", bound=_BinMapper) - # Author: Nicolas Hug class _BinMapper(TransformerMixin, BaseEstimator): @@ -37,6 +35,6 @@ class _BinMapper(TransformerMixin, BaseEstimator): random_state: RandomState | None | Int = None, n_threads: None | Int = None, ) -> None: ... - def fit(self: _BinMapper_Self, X: MatrixLike, y=None) -> _BinMapper_Self: ... + def fit(self, X: MatrixLike, y=None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... def make_known_categories_bitsets(self) -> tuple[ndarray, ndarray]: ... diff --git a/stubs/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.pyi b/stubs/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.pyi index 0cb82f94..98b9b9f0 100644 --- a/stubs/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.pyi +++ b/stubs/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.pyi @@ -5,7 +5,8 @@ from collections.abc import Mapping, Sequence from functools import partial as partial from numbers import Integral as Integral, Real as Real from timeit import default_timer as time -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -34,8 +35,6 @@ from ...utils.validation import check_consistent_length as check_consistent_leng from .common import G_H_DTYPE as G_H_DTYPE, X_DTYPE as X_DTYPE, Y_DTYPE as Y_DTYPE from .grower import TreeGrower as TreeGrower -BaseHistGradientBoosting_Self = TypeVar("BaseHistGradientBoosting_Self", bound=BaseHistGradientBoosting) - class BaseHistGradientBoosting(BaseEstimator, ABC): _parameter_constraints: ClassVar[dict] = ... @@ -65,11 +64,11 @@ class BaseHistGradientBoosting(BaseEstimator, ABC): random_state, ) -> None: ... def fit( - self: BaseHistGradientBoosting_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BaseHistGradientBoosting_Self: ... + ) -> Self: ... def n_iter_(self): ... class HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting): diff --git a/stubs/sklearn/ensemble/_iforest.pyi b/stubs/sklearn/ensemble/_iforest.pyi index 65e33456..ad658f64 100644 --- a/stubs/sklearn/ensemble/_iforest.pyi +++ b/stubs/sklearn/ensemble/_iforest.pyi @@ -1,6 +1,7 @@ import numbers from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self from warnings import warn as warn import numpy as np @@ -22,8 +23,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.validation import check_is_fitted as check_is_fitted from ._bagging import BaseBagging -IsolationForest_Self = TypeVar("IsolationForest_Self", bound=IsolationForest) - # Authors: Nicolas Goix # Alexandre Gramfort # License: BSD 3 clause @@ -57,11 +56,11 @@ class IsolationForest(OutlierMixin, BaseBagging): warm_start: bool = False, ) -> None: ... def fit( - self: IsolationForest_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> IsolationForest_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def decision_function(self, X: MatrixLike | ArrayLike) -> ndarray: ... def score_samples(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/ensemble/_stacking.pyi b/stubs/sklearn/ensemble/_stacking.pyi index 513cb4ee..4f398087 100644 --- a/stubs/sklearn/ensemble/_stacking.pyi +++ b/stubs/sklearn/ensemble/_stacking.pyi @@ -2,7 +2,8 @@ from abc import ABCMeta, abstractmethod from collections.abc import Iterable, Sequence from copy import deepcopy as deepcopy from numbers import Integral as Integral -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sparse @@ -32,10 +33,6 @@ from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted, column_or_1d as column_or_1d from ._base import _BaseHeterogeneousEnsemble -_BaseStacking_Self = TypeVar("_BaseStacking_Self", bound=_BaseStacking) -StackingRegressor_Self = TypeVar("StackingRegressor_Self", bound=StackingRegressor) -StackingClassifier_Self = TypeVar("StackingClassifier_Self", bound=StackingClassifier) - class _BaseStacking(TransformerMixin, _BaseHeterogeneousEnsemble, metaclass=ABCMeta): _parameter_constraints: ClassVar[dict] = ... @@ -52,11 +49,11 @@ class _BaseStacking(TransformerMixin, _BaseHeterogeneousEnsemble, metaclass=ABCM passthrough: bool = False, ) -> None: ... def fit( - self: _BaseStacking_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> _BaseStacking_Self | StackingClassifier: ... + ) -> Self | StackingClassifier: ... def n_features_in_(self): ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... def predict(self, X: MatrixLike | ArrayLike, **predict_params) -> ndarray: ... @@ -84,11 +81,11 @@ class StackingClassifier(ClassifierMixin, _BaseStacking): verbose: Int = 0, ) -> None: ... def fit( - self: StackingClassifier_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> StackingClassifier_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike, **predict_params) -> ndarray: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray | list[ndarray]: ... def decision_function(self, X: MatrixLike | ArrayLike) -> ndarray: ... @@ -113,9 +110,9 @@ class StackingRegressor(RegressorMixin, _BaseStacking): verbose: Int = 0, ) -> None: ... def fit( - self: StackingRegressor_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> StackingRegressor_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/ensemble/_voting.pyi b/stubs/sklearn/ensemble/_voting.pyi index 4cfadb7f..23db29fe 100644 --- a/stubs/sklearn/ensemble/_voting.pyi +++ b/stubs/sklearn/ensemble/_voting.pyi @@ -1,6 +1,7 @@ from abc import abstractmethod from numbers import Integral as Integral -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -17,9 +18,6 @@ from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted, column_or_1d as column_or_1d from ._base import _BaseHeterogeneousEnsemble -VotingClassifier_Self = TypeVar("VotingClassifier_Self", bound=VotingClassifier) -VotingRegressor_Self = TypeVar("VotingRegressor_Self", bound=VotingRegressor) - class _BaseVoting(TransformerMixin, _BaseHeterogeneousEnsemble): _parameter_constraints: ClassVar[dict] = ... @@ -49,11 +47,11 @@ class VotingClassifier(ClassifierMixin, _BaseVoting): verbose: bool = False, ) -> None: ... def fit( - self: VotingClassifier_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> VotingClassifier_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ArrayLike: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... def transform(self, X: MatrixLike | ArrayLike): ... @@ -74,11 +72,11 @@ class VotingRegressor(RegressorMixin, _BaseVoting): verbose: bool = False, ) -> None: ... def fit( - self: VotingRegressor_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> VotingRegressor_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/ensemble/_weight_boosting.pyi b/stubs/sklearn/ensemble/_weight_boosting.pyi index c6901744..d9bef5d7 100644 --- a/stubs/sklearn/ensemble/_weight_boosting.pyi +++ b/stubs/sklearn/ensemble/_weight_boosting.pyi @@ -2,7 +2,8 @@ import warnings from abc import ABCMeta, abstractmethod from collections.abc import Iterator from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -19,8 +20,6 @@ from ..utils.extmath import softmax as softmax, stable_cumsum as stable_cumsum from ..utils.validation import check_is_fitted as check_is_fitted, has_fit_parameter as has_fit_parameter from ._base import BaseEnsemble -BaseWeightBoosting_Self = TypeVar("BaseWeightBoosting_Self", bound=BaseWeightBoosting) - __all__ = [ "AdaBoostClassifier", "AdaBoostRegressor", @@ -41,11 +40,11 @@ class BaseWeightBoosting(BaseEnsemble, metaclass=ABCMeta): base_estimator: str = "deprecated", ) -> None: ... def fit( - self: BaseWeightBoosting_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BaseWeightBoosting_Self: ... + ) -> Self: ... def staged_score( self, X: MatrixLike | ArrayLike, diff --git a/stubs/sklearn/feature_extraction/_dict_vectorizer.pyi b/stubs/sklearn/feature_extraction/_dict_vectorizer.pyi index 0fd64527..b49901aa 100644 --- a/stubs/sklearn/feature_extraction/_dict_vectorizer.pyi +++ b/stubs/sklearn/feature_extraction/_dict_vectorizer.pyi @@ -2,7 +2,8 @@ from array import array as array from collections.abc import Iterable, Iterator, Mapping from numbers import Number as Number from operator import itemgetter as itemgetter -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -13,8 +14,6 @@ from .._typing import ArrayLike, MatrixLike from ..base import BaseEstimator, TransformerMixin from ..utils import check_array as check_array -DictVectorizer_Self = TypeVar("DictVectorizer_Self", bound=DictVectorizer) - # Authors: Lars Buitinck # Dan Blanchard # License: BSD 3 clause @@ -26,7 +25,7 @@ class DictVectorizer(TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, dtype=..., separator: str = "=", sparse: bool = True, sort: bool = True) -> None: ... - def fit(self: DictVectorizer_Self, X: Mapping | Iterable[Mapping], y: Any = None) -> DictVectorizer_Self: ... + def fit(self, X: Mapping | Iterable[Mapping], y: Any = None) -> Self: ... def fit_transform( self, X: Iterator[Any] | Mapping | Iterable[Mapping] | list[dict[str, int]], @@ -35,4 +34,4 @@ class DictVectorizer(TransformerMixin, BaseEstimator): def inverse_transform(self, X: MatrixLike | ArrayLike, dict_type=...) -> list[Mapping]: ... def transform(self, X: ArrayLike | Mapping[str, ArrayLike] | Iterator[Mapping[str, ArrayLike]]) -> ndarray | spmatrix: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... - def restrict(self: DictVectorizer_Self, support: ArrayLike, indices: bool = False) -> DictVectorizer_Self: ... + def restrict(self, support: ArrayLike, indices: bool = False) -> Self: ... diff --git a/stubs/sklearn/feature_extraction/_hash.pyi b/stubs/sklearn/feature_extraction/_hash.pyi index 24601dcc..af0b26b2 100644 --- a/stubs/sklearn/feature_extraction/_hash.pyi +++ b/stubs/sklearn/feature_extraction/_hash.pyi @@ -1,7 +1,8 @@ from collections.abc import Iterator from itertools import chain as chain from numbers import Integral as Integral -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -13,8 +14,6 @@ from ..base import BaseEstimator, TransformerMixin from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ._hashing_fast import transform as _hashing_transform -FeatureHasher_Self = TypeVar("FeatureHasher_Self", bound=FeatureHasher) - # Author: Lars Buitinck # License: BSD 3 clause @@ -29,5 +28,5 @@ class FeatureHasher(TransformerMixin, BaseEstimator): dtype: dtype = ..., alternate_sign: bool = True, ) -> None: ... - def fit(self: FeatureHasher_Self, X: Any = None, y: Any = None) -> FeatureHasher_Self: ... + def fit(self, X: Any = None, y: Any = None) -> Self: ... def transform(self, raw_X: Iterator[Any] | Iterator[Iterator]) -> spmatrix: ... diff --git a/stubs/sklearn/feature_extraction/image.pyi b/stubs/sklearn/feature_extraction/image.pyi index c9eb59e6..4ca42b95 100644 --- a/stubs/sklearn/feature_extraction/image.pyi +++ b/stubs/sklearn/feature_extraction/image.pyi @@ -1,6 +1,7 @@ from itertools import product as product from numbers import Integral as Integral, Number as Number, Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -15,8 +16,6 @@ from ..base import BaseEstimator from ..utils import check_array as check_array, check_random_state as check_random_state from ..utils._param_validation import Interval as Interval -PatchExtractor_Self = TypeVar("PatchExtractor_Self", bound=PatchExtractor) - __all__ = [ "PatchExtractor", "extract_patches_2d", @@ -50,5 +49,5 @@ class PatchExtractor(BaseEstimator): max_patches: float | None = None, random_state: RandomState | None | Int = None, ) -> None: ... - def fit(self: PatchExtractor_Self, X: MatrixLike, y: Any = None) -> PatchExtractor_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/feature_extraction/text.pyi b/stubs/sklearn/feature_extraction/text.pyi index b080504d..426f190c 100644 --- a/stubs/sklearn/feature_extraction/text.pyi +++ b/stubs/sklearn/feature_extraction/text.pyi @@ -7,7 +7,8 @@ from collections.abc import Iterable, Mapping from functools import partial from numbers import Integral as Integral, Real as Real from operator import itemgetter as itemgetter -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -23,11 +24,6 @@ from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_array as chec from ._hash import FeatureHasher as FeatureHasher from ._stop_words import ENGLISH_STOP_WORDS -TfidfVectorizer_Self = TypeVar("TfidfVectorizer_Self", bound=TfidfVectorizer) -HashingVectorizer_Self = TypeVar("HashingVectorizer_Self", bound=HashingVectorizer) -CountVectorizer_Self = TypeVar("CountVectorizer_Self", bound=CountVectorizer) -TfidfTransformer_Self = TypeVar("TfidfTransformer_Self", bound=TfidfTransformer) - # Authors: Olivier Grisel # Mathieu Blondel # Lars Buitinck @@ -84,8 +80,8 @@ class HashingVectorizer(TransformerMixin, _VectorizerMixin, BaseEstimator, auto_ alternate_sign: bool = True, dtype=..., ) -> None: ... - def partial_fit(self: HashingVectorizer_Self, X: MatrixLike, y: Any = None) -> HashingVectorizer_Self: ... - def fit(self: HashingVectorizer_Self, X: list[str] | MatrixLike, y: Any = None) -> HashingVectorizer_Self: ... + def partial_fit(self, X: MatrixLike, y: Any = None) -> Self: ... + def fit(self, X: list[str] | MatrixLike, y: Any = None) -> Self: ... def transform(self, X: Iterable[str]) -> spmatrix: ... def fit_transform(self, X: list[str] | Iterable[str], y: Any = None) -> spmatrix: ... @@ -117,7 +113,7 @@ class CountVectorizer(_VectorizerMixin, BaseEstimator): binary: bool = False, dtype=..., ) -> None: ... - def fit(self: CountVectorizer_Self, raw_documents: Iterable, y=None) -> CountVectorizer_Self: ... + def fit(self, raw_documents: Iterable, y=None) -> Self: ... def fit_transform( self, raw_documents: list[str] | ndarray | Iterable, @@ -141,7 +137,7 @@ class TfidfTransformer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator, au smooth_idf: bool = True, sublinear_tf: bool = False, ) -> None: ... - def fit(self: TfidfTransformer_Self, X: MatrixLike, y: None | ndarray | list[Int] = None) -> TfidfTransformer_Self: ... + def fit(self, X: MatrixLike, y: None | ndarray | list[Int] = None) -> Self: ... def transform(self, X: MatrixLike, copy: bool = True) -> spmatrix: ... @property def idf_(self) -> ndarray: ... @@ -188,6 +184,6 @@ class TfidfVectorizer(CountVectorizer): def idf_(self) -> ndarray: ... @idf_.setter def idf_(self, value) -> ndarray: ... - def fit(self: TfidfVectorizer_Self, raw_documents: Iterable, y=None) -> TfidfVectorizer_Self: ... + def fit(self, raw_documents: Iterable, y=None) -> Self: ... def fit_transform(self, raw_documents: list[str] | ndarray | Iterable, y: None | ndarray = None) -> spmatrix: ... def transform(self, raw_documents: list[str] | ndarray | Iterable) -> spmatrix: ... diff --git a/stubs/sklearn/feature_selection/_from_model.pyi b/stubs/sklearn/feature_selection/_from_model.pyi index 75c943c1..4936f3e0 100644 --- a/stubs/sklearn/feature_selection/_from_model.pyi +++ b/stubs/sklearn/feature_selection/_from_model.pyi @@ -1,6 +1,7 @@ from copy import deepcopy as deepcopy from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, TypeVar +from typing import Any, Callable, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -13,8 +14,6 @@ from ..utils.metaestimators import available_if as available_if from ..utils.validation import check_is_fitted as check_is_fitted, check_scalar as check_scalar from ._base import SelectorMixin -SelectFromModel_Self = TypeVar("SelectFromModel_Self", bound=SelectFromModel) - # Authors: Gilles Louppe, Mathieu Blondel, Maheshakya Wijewardena # License: BSD 3 clause @@ -36,18 +35,18 @@ class SelectFromModel(MetaEstimatorMixin, SelectorMixin, BaseEstimator): importance_getter: str | Callable = "auto", ) -> None: ... def fit( - self: SelectFromModel_Self, + self, X: MatrixLike, y: None | ArrayLike = None, **fit_params, - ) -> SelectFromModel_Self: ... + ) -> Self: ... @property def threshold_(self) -> float: ... def partial_fit( - self: SelectFromModel_Self, + self, X: MatrixLike, y: None | ArrayLike = None, **fit_params, - ) -> SelectFromModel_Self: ... + ) -> Self: ... @property def n_features_in_(self) -> int: ... diff --git a/stubs/sklearn/feature_selection/_rfe.pyi b/stubs/sklearn/feature_selection/_rfe.pyi index 81cd3a03..22818ab9 100644 --- a/stubs/sklearn/feature_selection/_rfe.pyi +++ b/stubs/sklearn/feature_selection/_rfe.pyi @@ -1,6 +1,7 @@ from collections.abc import Iterable from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, TypeVar +from typing import Callable, ClassVar +from typing_extensions import Self import numpy as np from joblib import effective_n_jobs as effective_n_jobs @@ -17,9 +18,6 @@ from ..utils.parallel import Parallel as Parallel, delayed as delayed from ..utils.validation import check_is_fitted as check_is_fitted from ._base import SelectorMixin -RFECV_Self = TypeVar("RFECV_Self", bound=RFECV) -RFE_Self = TypeVar("RFE_Self", bound=RFE) - # Authors: Alexandre Gramfort # Vincent Michel # Gilles Louppe @@ -47,7 +45,7 @@ class RFE(SelectorMixin, MetaEstimatorMixin, BaseEstimator): ) -> None: ... @property def classes_(self) -> ndarray: ... - def fit(self: RFE_Self, X: MatrixLike | ArrayLike, y: ArrayLike, **fit_params) -> RFE_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: ArrayLike, **fit_params) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... def score(self, X: MatrixLike, y: ArrayLike, **fit_params) -> float: ... def decision_function(self, X: MatrixLike) -> ndarray: ... @@ -79,8 +77,8 @@ class RFECV(RFE): importance_getter: str | Callable = "auto", ) -> None: ... def fit( - self: RFECV_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, groups: None | ArrayLike = None, - ) -> RFECV_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/feature_selection/_sequential.pyi b/stubs/sklearn/feature_selection/_sequential.pyi index b2e23e65..fe2b9c3b 100644 --- a/stubs/sklearn/feature_selection/_sequential.pyi +++ b/stubs/sklearn/feature_selection/_sequential.pyi @@ -1,7 +1,8 @@ import warnings from collections.abc import Iterable from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,8 +15,6 @@ from ..utils._param_validation import HasMethods as HasMethods, Hidden as Hidden from ..utils.validation import check_is_fitted as check_is_fitted from ._base import SelectorMixin -SequentialFeatureSelector_Self = TypeVar("SequentialFeatureSelector_Self", bound=SequentialFeatureSelector) - class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator): support_: ndarray = ... n_features_to_select_: int = ... @@ -35,6 +34,4 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator cv: Iterable | int | BaseCrossValidator = 5, n_jobs: None | Int = None, ) -> None: ... - def fit( - self: SequentialFeatureSelector_Self, X: MatrixLike, y: None | ArrayLike = None - ) -> SequentialFeatureSelector_Self: ... + def fit(self, X: MatrixLike, y: None | ArrayLike = None) -> Self: ... diff --git a/stubs/sklearn/feature_selection/_univariate_selection.pyi b/stubs/sklearn/feature_selection/_univariate_selection.pyi index 66bf446f..2880c33b 100644 --- a/stubs/sklearn/feature_selection/_univariate_selection.pyi +++ b/stubs/sklearn/feature_selection/_univariate_selection.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib.memory import MemorizedFunc @@ -23,8 +24,6 @@ from ..utils.extmath import row_norms as row_norms, safe_sparse_dot as safe_spar from ..utils.validation import check_is_fitted as check_is_fitted from ._base import SelectorMixin -_BaseFilter_Self = TypeVar("_BaseFilter_Self", bound=_BaseFilter) - # Authors: V. Michel, B. Thirion, G. Varoquaux, A. Gramfort, E. Duchesnay. # L. Buitinck, A. Joly # License: BSD 3 clause @@ -50,7 +49,7 @@ class _BaseFilter(SelectorMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, score_func: Callable | MemorizedFunc) -> None: ... - def fit(self: _BaseFilter_Self, X: MatrixLike, y: ArrayLike) -> _BaseFilter_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... ###################################################################### # Specific filters diff --git a/stubs/sklearn/feature_selection/_variance_threshold.pyi b/stubs/sklearn/feature_selection/_variance_threshold.pyi index 74eb25b7..423921e7 100644 --- a/stubs/sklearn/feature_selection/_variance_threshold.pyi +++ b/stubs/sklearn/feature_selection/_variance_threshold.pyi @@ -1,5 +1,6 @@ from numbers import Real as Real -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -11,8 +12,6 @@ from ..utils.sparsefuncs import mean_variance_axis as mean_variance_axis, min_ma from ..utils.validation import check_is_fitted as check_is_fitted from ._base import SelectorMixin -VarianceThreshold_Self = TypeVar("VarianceThreshold_Self", bound=VarianceThreshold) - # Author: Lars Buitinck # License: 3-clause BSD @@ -24,4 +23,4 @@ class VarianceThreshold(SelectorMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, threshold: Float = 0.0) -> None: ... - def fit(self: VarianceThreshold_Self, X: MatrixLike, y: Any = None) -> VarianceThreshold_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... diff --git a/stubs/sklearn/gaussian_process/_gpc.pyi b/stubs/sklearn/gaussian_process/_gpc.pyi index ce1056da..e6bad16c 100644 --- a/stubs/sklearn/gaussian_process/_gpc.pyi +++ b/stubs/sklearn/gaussian_process/_gpc.pyi @@ -1,6 +1,7 @@ from numbers import Integral as Integral from operator import itemgetter as itemgetter -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.optimize @@ -18,12 +19,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.validation import check_is_fitted as check_is_fitted from .kernels import RBF as RBF, CompoundKernel as CompoundKernel, ConstantKernel as C, Kernel, Product -_BinaryGaussianProcessClassifierLaplace_Self = TypeVar( - "_BinaryGaussianProcessClassifierLaplace_Self", - bound=_BinaryGaussianProcessClassifierLaplace, -) -GaussianProcessClassifier_Self = TypeVar("GaussianProcessClassifier_Self", bound=GaussianProcessClassifier) - # Values required for approximating the logistic sigmoid by # error functions. coefs are obtained via: # x = np.array([0, 0.6, 2, 3.5, 4.5, np.inf]) @@ -55,10 +50,10 @@ class _BinaryGaussianProcessClassifierLaplace(BaseEstimator): random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: _BinaryGaussianProcessClassifierLaplace_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, - ) -> _BinaryGaussianProcessClassifierLaplace_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... def log_marginal_likelihood( @@ -91,7 +86,7 @@ class GaussianProcessClassifier(ClassifierMixin, BaseEstimator): multi_class: Literal["one_vs_rest", "one_vs_one"] = "one_vs_rest", n_jobs: None | Int = None, ) -> None: ... - def fit(self: GaussianProcessClassifier_Self, X: MatrixLike | ArrayLike, y: ArrayLike) -> GaussianProcessClassifier_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... @property diff --git a/stubs/sklearn/gaussian_process/_gpr.pyi b/stubs/sklearn/gaussian_process/_gpr.pyi index 74368339..df0ccc3e 100644 --- a/stubs/sklearn/gaussian_process/_gpr.pyi +++ b/stubs/sklearn/gaussian_process/_gpr.pyi @@ -1,7 +1,8 @@ import warnings from numbers import Integral as Integral, Real as Real from operator import itemgetter as itemgetter -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.optimize @@ -15,8 +16,6 @@ from ..utils import check_random_state as check_random_state from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from .kernels import RBF as RBF, ConstantKernel as C, Kernel -GaussianProcessRegressor_Self = TypeVar("GaussianProcessRegressor_Self", bound=GaussianProcessRegressor) - # Authors: Jan Hendrik Metzen # Modified by: Pete Green # License: BSD 3 clause @@ -48,10 +47,10 @@ class GaussianProcessRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator): random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: GaussianProcessRegressor_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, - ) -> GaussianProcessRegressor_Self: ... + ) -> Self: ... def predict( self, X: MatrixLike | ArrayLike, diff --git a/stubs/sklearn/gaussian_process/kernels.pyi b/stubs/sklearn/gaussian_process/kernels.pyi index 55861dd9..1951b54e 100644 --- a/stubs/sklearn/gaussian_process/kernels.pyi +++ b/stubs/sklearn/gaussian_process/kernels.pyi @@ -4,7 +4,7 @@ from abc import ABCMeta, abstractmethod from collections import namedtuple from collections.abc import Sequence from inspect import signature as signature -from typing import Callable, Literal, TypeVar +from typing import Callable, Literal from typing_extensions import Self import numpy as np @@ -17,9 +17,6 @@ from ..base import clone as clone from ..exceptions import ConvergenceWarning as ConvergenceWarning from ..metrics.pairwise import pairwise_kernels as pairwise_kernels -Kernel_Self = TypeVar("Kernel_Self", bound=Kernel) -Hyperparameter_Self = TypeVar("Hyperparameter_Self", bound=Hyperparameter) - class Hyperparameter(namedtuple("Hyperparameter", ("name", "value_type", "bounds", "n_elements", "fixed"))): fixed: bool = ... n_elements: int = ... @@ -52,7 +49,7 @@ class Hyperparameter(namedtuple("Hyperparameter", ("name", "value_type", "bounds class Kernel(metaclass=ABCMeta): def get_params(self, deep: bool = True) -> dict: ... - def set_params(self: Kernel_Self, **params) -> Kernel_Self: ... + def set_params(self, **params) -> Self: ... def clone_with_theta(self, theta: ArrayLike): ... def n_dims(self) -> int: ... def hyperparameters(self) -> list[Hyperparameter]: ... diff --git a/stubs/sklearn/impute/_base.pyi b/stubs/sklearn/impute/_base.pyi index 1cc6b872..67e924f5 100644 --- a/stubs/sklearn/impute/_base.pyi +++ b/stubs/sklearn/impute/_base.pyi @@ -1,7 +1,8 @@ import numbers import warnings from collections import Counter as Counter -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np import numpy.ma as ma @@ -15,9 +16,6 @@ from ..utils import is_scalar_nan as is_scalar_nan from ..utils._param_validation import Hidden as Hidden, StrOptions as StrOptions from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted -SimpleImputer_Self = TypeVar("SimpleImputer_Self", bound=SimpleImputer) -MissingIndicator_Self = TypeVar("MissingIndicator_Self", bound=MissingIndicator) - # Authors: Nicolas Tresegnie # Sergey Feldman # License: BSD 3 clause @@ -52,7 +50,7 @@ class SimpleImputer(_BaseImputer): add_indicator: bool = False, keep_empty_features: bool = False, ) -> None: ... - def fit(self: SimpleImputer_Self, X: MatrixLike, y: Any = None) -> SimpleImputer_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray | spmatrix: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... @@ -72,7 +70,7 @@ class MissingIndicator(TransformerMixin, BaseEstimator): sparse: Literal["auto"] | bool = "auto", error_on_new: bool = True, ) -> None: ... - def fit(self: MissingIndicator_Self, X: MatrixLike | ArrayLike, y: Any = None) -> MissingIndicator_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray | spmatrix: ... def fit_transform(self, X: MatrixLike | ArrayLike, y: Any = None) -> ndarray | spmatrix: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/impute/_iterative.pyi b/stubs/sklearn/impute/_iterative.pyi index cef3e9d3..49d10bf0 100644 --- a/stubs/sklearn/impute/_iterative.pyi +++ b/stubs/sklearn/impute/_iterative.pyi @@ -2,7 +2,8 @@ import warnings from collections import namedtuple as namedtuple from numbers import Integral as Integral, Real as Real from time import time as time -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -19,8 +20,6 @@ from ..utils._param_validation import HasMethods as HasMethods, Interval as Inte from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted from ._base import MissingIndicator, SimpleImputer, _BaseImputer -IterativeImputer_Self = TypeVar("IterativeImputer_Self", bound=IterativeImputer) - _ImputerTriplet = ... class IterativeImputer(_BaseImputer): @@ -56,5 +55,5 @@ class IterativeImputer(_BaseImputer): ) -> None: ... def fit_transform(self, X: MatrixLike, y: Any = None) -> ndarray: ... def transform(self, X: MatrixLike) -> ndarray: ... - def fit(self: IterativeImputer_Self, X: MatrixLike, y: Any = None) -> IterativeImputer_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/impute/_knn.pyi b/stubs/sklearn/impute/_knn.pyi index 4d1d5f14..26537bec 100644 --- a/stubs/sklearn/impute/_knn.pyi +++ b/stubs/sklearn/impute/_knn.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -11,8 +12,6 @@ from ..utils._param_validation import Hidden as Hidden, Interval as Interval, St from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted from ._base import MissingIndicator, _BaseImputer -KNNImputer_Self = TypeVar("KNNImputer_Self", bound=KNNImputer) - # Authors: Ashim Bhattarai # Thomas J Fan # License: BSD 3 clause @@ -35,6 +34,6 @@ class KNNImputer(_BaseImputer): add_indicator: bool = False, keep_empty_features: bool = False, ) -> None: ... - def fit(self: KNNImputer_Self, X: list[list[int | float]] | MatrixLike, y: Any = None) -> KNNImputer_Self: ... + def fit(self, X: list[list[int | float]] | MatrixLike, y: Any = None) -> Self: ... def transform(self, X: list[list[int | float]] | MatrixLike) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/isotonic.pyi b/stubs/sklearn/isotonic.pyi index b527c8ba..6e22bfc9 100644 --- a/stubs/sklearn/isotonic.pyi +++ b/stubs/sklearn/isotonic.pyi @@ -1,7 +1,8 @@ import math import warnings from numbers import Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -13,8 +14,6 @@ from .base import BaseEstimator, RegressorMixin, TransformerMixin from .utils import check_array as check_array, check_consistent_length as check_consistent_length from .utils._param_validation import Interval as Interval, StrOptions as StrOptions -IsotonicRegression_Self = TypeVar("IsotonicRegression_Self", bound=IsotonicRegression) - # Authors: Fabian Pedregosa # Alexandre Gramfort # Nelle Varoquaux @@ -51,11 +50,11 @@ class IsotonicRegression(RegressorMixin, TransformerMixin, BaseEstimator): out_of_bounds: Literal["nan", "clip", "raise"] = "nan", ) -> None: ... def fit( - self: IsotonicRegression_Self, + self, X: ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> IsotonicRegression_Self: ... + ) -> Self: ... def transform(self, T: ArrayLike) -> ndarray: ... def predict(self, T: ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/kernel_approximation.pyi b/stubs/sklearn/kernel_approximation.pyi index f68aebf8..2102718b 100644 --- a/stubs/sklearn/kernel_approximation.pyi +++ b/stubs/sklearn/kernel_approximation.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, TypeVar +from typing import Callable, ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -22,12 +23,6 @@ from .utils._param_validation import Interval as Interval, StrOptions as StrOpti from .utils.extmath import safe_sparse_dot as safe_sparse_dot from .utils.validation import check_is_fitted as check_is_fitted, check_non_negative as check_non_negative -SkewedChi2Sampler_Self = TypeVar("SkewedChi2Sampler_Self", bound=SkewedChi2Sampler) -PolynomialCountSketch_Self = TypeVar("PolynomialCountSketch_Self", bound=PolynomialCountSketch) -AdditiveChi2Sampler_Self = TypeVar("AdditiveChi2Sampler_Self", bound=AdditiveChi2Sampler) -RBFSampler_Self = TypeVar("RBFSampler_Self", bound=RBFSampler) -Nystroem_Self = TypeVar("Nystroem_Self", bound=Nystroem) - class PolynomialCountSketch(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): feature_names_in_: ndarray = ... n_features_in_: int = ... @@ -46,10 +41,10 @@ class PolynomialCountSketch(ClassNamePrefixFeaturesOutMixin, TransformerMixin, B random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: PolynomialCountSketch_Self, + self, X: MatrixLike | ArrayLike, y: None | MatrixLike | ArrayLike = None, - ) -> PolynomialCountSketch_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... class RBFSampler(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): @@ -67,7 +62,7 @@ class RBFSampler(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimato n_components: Int = 100, random_state: RandomState | None | Int = None, ) -> None: ... - def fit(self: RBFSampler_Self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None) -> RBFSampler_Self: ... + def fit(self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... class SkewedChi2Sampler(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): @@ -86,10 +81,10 @@ class SkewedChi2Sampler(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseE random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: SkewedChi2Sampler_Self, + self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None, - ) -> SkewedChi2Sampler_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... class AdditiveChi2Sampler(TransformerMixin, BaseEstimator): @@ -101,10 +96,10 @@ class AdditiveChi2Sampler(TransformerMixin, BaseEstimator): def __init__(self, *, sample_steps: Int = 2, sample_interval: None | Float = None) -> None: ... def fit( - self: AdditiveChi2Sampler_Self, + self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None, - ) -> AdditiveChi2Sampler_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike) -> ndarray | spmatrix: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... @@ -129,5 +124,5 @@ class Nystroem(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator) random_state: RandomState | None | Int = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: Nystroem_Self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None) -> Nystroem_Self: ... + def fit(self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/kernel_ridge.pyi b/stubs/sklearn/kernel_ridge.pyi index 316d9895..d4389baf 100644 --- a/stubs/sklearn/kernel_ridge.pyi +++ b/stubs/sklearn/kernel_ridge.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, TypeVar +from typing import Callable, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -11,8 +12,6 @@ from .metrics.pairwise import PAIRWISE_KERNEL_FUNCTIONS as PAIRWISE_KERNEL_FUNCT from .utils._param_validation import Interval as Interval, StrOptions as StrOptions from .utils.validation import check_is_fitted as check_is_fitted -KernelRidge_Self = TypeVar("KernelRidge_Self", bound=KernelRidge) - class KernelRidge(MultiOutputMixin, RegressorMixin, BaseEstimator): feature_names_in_: ndarray = ... n_features_in_: int = ... @@ -32,9 +31,9 @@ class KernelRidge(MultiOutputMixin, RegressorMixin, BaseEstimator): kernel_params: None | dict = None, ) -> None: ... def fit( - self: KernelRidge_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> KernelRidge_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/linear_model/_base.pyi b/stubs/sklearn/linear_model/_base.pyi index 08967532..f0628092 100644 --- a/stubs/sklearn/linear_model/_base.pyi +++ b/stubs/sklearn/linear_model/_base.pyi @@ -2,7 +2,8 @@ import numbers import warnings from abc import ABCMeta, abstractmethod from numbers import Integral as Integral -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -23,9 +24,6 @@ from ..utils.sparsefuncs import inplace_column_scale as inplace_column_scale, me from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted from ._stochastic_gradient import SGDClassifier -LinearRegression_Self = TypeVar("LinearRegression_Self", bound=LinearRegression) -SparseCoefMixin_Self = TypeVar("SparseCoefMixin_Self", bound=SparseCoefMixin) - # TODO: bayesian_ridge_regression and bayesian_regression_ard # should be squashed into its respective objects. @@ -50,8 +48,8 @@ class LinearClassifierMixin(ClassifierMixin): def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... class SparseCoefMixin: - def densify(self: SparseCoefMixin_Self) -> SparseCoefMixin_Self: ... - def sparsify(self: SparseCoefMixin_Self) -> SGDClassifier | SparseCoefMixin_Self: ... + def densify(self) -> Self: ... + def sparsify(self) -> SGDClassifier | Self: ... class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): feature_names_in_: ndarray = ... @@ -72,8 +70,8 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): positive: bool = False, ) -> None: ... def fit( - self: LinearRegression_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> LinearRegression_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/linear_model/_bayes.pyi b/stubs/sklearn/linear_model/_bayes.pyi index 03378950..c7a91a1a 100644 --- a/stubs/sklearn/linear_model/_bayes.pyi +++ b/stubs/sklearn/linear_model/_bayes.pyi @@ -1,6 +1,7 @@ from math import log as log from numbers import Integral as Integral, Real as Real -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -13,9 +14,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.extmath import fast_logdet as fast_logdet from ._base import LinearModel -BayesianRidge_Self = TypeVar("BayesianRidge_Self", bound=BayesianRidge) -ARDRegression_Self = TypeVar("ARDRegression_Self", bound=ARDRegression) - ############################################################################### # BayesianRidge regression @@ -51,11 +49,11 @@ class BayesianRidge(RegressorMixin, LinearModel): verbose: bool = False, ) -> None: ... def fit( - self: BayesianRidge_Self, + self, X: ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BayesianRidge_Self: ... + ) -> Self: ... def predict( self, X: MatrixLike | ArrayLike, return_std: bool = False ) -> ArrayLike | tuple[ndarray, ndarray] | tuple[ArrayLike, ArrayLike]: ... @@ -92,7 +90,7 @@ class ARDRegression(RegressorMixin, LinearModel): copy_X: bool = True, verbose: bool = False, ) -> None: ... - def fit(self: ARDRegression_Self, X: MatrixLike, y: ArrayLike) -> ARDRegression_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... def predict( self, X: MatrixLike | ArrayLike, return_std: bool = False ) -> tuple[ndarray, ndarray] | tuple[ArrayLike, ArrayLike]: ... diff --git a/stubs/sklearn/linear_model/_coordinate_descent.pyi b/stubs/sklearn/linear_model/_coordinate_descent.pyi index afa93a40..1b78da1b 100644 --- a/stubs/sklearn/linear_model/_coordinate_descent.pyi +++ b/stubs/sklearn/linear_model/_coordinate_descent.pyi @@ -5,7 +5,8 @@ from abc import ABC, abstractmethod from collections.abc import Iterable, Sequence from functools import partial as partial from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import effective_n_jobs as effective_n_jobs @@ -30,12 +31,6 @@ from ..utils.validation import ( ) from ._base import LinearModel -LinearModelCV_Self = TypeVar("LinearModelCV_Self", bound=LinearModelCV) -MultiTaskElasticNetCV_Self = TypeVar("MultiTaskElasticNetCV_Self", bound=MultiTaskElasticNetCV) -MultiTaskLassoCV_Self = TypeVar("MultiTaskLassoCV_Self", bound=MultiTaskLassoCV) -ElasticNet_Self = TypeVar("ElasticNet_Self", bound=ElasticNet) -MultiTaskElasticNet_Self = TypeVar("MultiTaskElasticNet_Self", bound=MultiTaskElasticNet) - # Author: Alexandre Gramfort # Fabian Pedregosa # Olivier Grisel @@ -109,12 +104,12 @@ class ElasticNet(MultiOutputMixin, RegressorMixin, LinearModel): selection: Literal["cyclic", "random"] = "cyclic", ) -> None: ... def fit( - self: ElasticNet_Self, + self, X: coo_matrix | MatrixLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, check_input: bool = True, - ) -> ElasticNet_Self: ... + ) -> Self: ... @property def sparse_coef_(self) -> spmatrix: ... @@ -174,11 +169,11 @@ class LinearModelCV(MultiOutputMixin, LinearModel, ABC): @abstractmethod def path(X, y, **kwargs): ... def fit( - self: LinearModelCV_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> LinearModelCV_Self | LassoCV: ... + ) -> Self | LassoCV: ... class LassoCV(RegressorMixin, LinearModelCV): feature_names_in_: ndarray = ... @@ -276,7 +271,7 @@ class MultiTaskElasticNet(Lasso): random_state: RandomState | None | Int = None, selection: Literal["cyclic", "random"] = "cyclic", ) -> None: ... - def fit(self: MultiTaskElasticNet_Self, X: ArrayLike, y: MatrixLike) -> MultiTaskElasticNet_Self | MultiTaskLasso: ... + def fit(self, X: ArrayLike, y: MatrixLike) -> Self | MultiTaskLasso: ... class MultiTaskLasso(MultiTaskElasticNet): feature_names_in_: ndarray = ... @@ -339,7 +334,7 @@ class MultiTaskElasticNetCV(RegressorMixin, LinearModelCV): # This is necessary as LinearModelCV now supports sample_weight while # MultiTaskElasticNet does not (yet). - def fit(self: MultiTaskElasticNetCV_Self, X: ArrayLike, y: MatrixLike) -> MultiTaskElasticNetCV_Self: ... + def fit(self, X: ArrayLike, y: MatrixLike) -> Self: ... class MultiTaskLassoCV(RegressorMixin, LinearModelCV): feature_names_in_: ndarray = ... @@ -375,4 +370,4 @@ class MultiTaskLassoCV(RegressorMixin, LinearModelCV): # This is necessary as LinearModelCV now supports sample_weight while # MultiTaskElasticNet does not (yet). - def fit(self: MultiTaskLassoCV_Self, X: ArrayLike, y: MatrixLike) -> MultiTaskLassoCV_Self: ... + def fit(self, X: ArrayLike, y: MatrixLike) -> Self: ... diff --git a/stubs/sklearn/linear_model/_glm/glm.pyi b/stubs/sklearn/linear_model/_glm/glm.pyi index fa7b223b..4c7a27c7 100644 --- a/stubs/sklearn/linear_model/_glm/glm.pyi +++ b/stubs/sklearn/linear_model/_glm/glm.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.optimize @@ -22,8 +23,6 @@ from ...utils.validation import check_is_fitted as check_is_fitted from .._linear_loss import LinearModelLoss as LinearModelLoss from ._newton_solver import NewtonCholeskySolver as NewtonCholeskySolver, NewtonSolver -_GeneralizedLinearRegressor_Self = TypeVar("_GeneralizedLinearRegressor_Self", bound=_GeneralizedLinearRegressor) - class _GeneralizedLinearRegressor(RegressorMixin, BaseEstimator): _base_loss: BaseLoss = ... n_iter_: int = ... @@ -47,11 +46,11 @@ class _GeneralizedLinearRegressor(RegressorMixin, BaseEstimator): verbose: Int = 0, ) -> None: ... def fit( - self: _GeneralizedLinearRegressor_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> _GeneralizedLinearRegressor_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def score( self, diff --git a/stubs/sklearn/linear_model/_huber.pyi b/stubs/sklearn/linear_model/_huber.pyi index bbdc6c4f..d2c7e7ac 100644 --- a/stubs/sklearn/linear_model/_huber.pyi +++ b/stubs/sklearn/linear_model/_huber.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -12,8 +13,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.extmath import safe_sparse_dot as safe_sparse_dot from ._base import LinearModel -HuberRegressor_Self = TypeVar("HuberRegressor_Self", bound=HuberRegressor) - # Authors: Manoj Kumar mks542@nyu.edu # License: BSD 3 clause @@ -39,8 +38,8 @@ class HuberRegressor(LinearModel, RegressorMixin, BaseEstimator): tol: Float = 1e-05, ) -> None: ... def fit( - self: HuberRegressor_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> HuberRegressor_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/linear_model/_least_angle.pyi b/stubs/sklearn/linear_model/_least_angle.pyi index fbc2ae97..056916b7 100644 --- a/stubs/sklearn/linear_model/_least_angle.pyi +++ b/stubs/sklearn/linear_model/_least_angle.pyi @@ -3,7 +3,8 @@ import warnings from collections.abc import Iterable from math import log as log from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -20,10 +21,6 @@ from ..utils._param_validation import Hidden as Hidden, Interval as Interval, St from ..utils.parallel import Parallel as Parallel, delayed as delayed from ._base import LinearModel, LinearRegression as LinearRegression -LassoLarsIC_Self = TypeVar("LassoLarsIC_Self", bound=LassoLarsIC) -Lars_Self = TypeVar("Lars_Self", bound=Lars) -LarsCV_Self = TypeVar("LarsCV_Self", bound=LarsCV) - SOLVE_TRIANGULAR_ARGS: dict = ... def lars_path( @@ -93,11 +90,11 @@ class Lars(MultiOutputMixin, RegressorMixin, LinearModel): random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: Lars_Self, + self, X: MatrixLike, y: MatrixLike | ArrayLike, Xy: None | MatrixLike | ArrayLike = None, - ) -> Lars_Self: ... + ) -> Self: ... class LassoLars(Lars): feature_names_in_: ndarray = ... @@ -161,7 +158,7 @@ class LarsCV(Lars): eps: Float = ..., copy_X: bool = True, ) -> None: ... - def fit(self: LarsCV_Self, X: MatrixLike, y: ArrayLike) -> LarsCV_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... class LassoLarsCV(LarsCV): feature_names_in_: ndarray = ... @@ -223,4 +220,4 @@ class LassoLarsIC(LassoLars): positive: bool = False, noise_variance: None | Float = None, ) -> None: ... - def fit(self: LassoLarsIC_Self, X: MatrixLike, y: ArrayLike, copy_X: None | bool = None) -> LassoLarsIC_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike, copy_X: None | bool = None) -> Self: ... diff --git a/stubs/sklearn/linear_model/_logistic.pyi b/stubs/sklearn/linear_model/_logistic.pyi index a187fd36..22f56875 100644 --- a/stubs/sklearn/linear_model/_logistic.pyi +++ b/stubs/sklearn/linear_model/_logistic.pyi @@ -2,7 +2,8 @@ import numbers import warnings from collections.abc import Mapping, Sequence from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import effective_n_jobs as effective_n_jobs @@ -31,9 +32,6 @@ from ._glm.glm import NewtonCholeskySolver as NewtonCholeskySolver from ._linear_loss import LinearModelLoss as LinearModelLoss from ._sag import sag_solver as sag_solver -LogisticRegressionCV_Self = TypeVar("LogisticRegressionCV_Self", bound=LogisticRegressionCV) -LogisticRegression_Self = TypeVar("LogisticRegression_Self", bound=LogisticRegression) - # Author: Gael Varoquaux # Fabian Pedregosa # Alexandre Gramfort @@ -74,11 +72,11 @@ class LogisticRegression(LinearClassifierMixin, SparseCoefMixin, BaseEstimator): l1_ratio: None | Float = None, ) -> None: ... def fit( - self: LogisticRegression_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> LogisticRegression_Self: ... + ) -> Self: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... def predict_log_proba(self, X: MatrixLike) -> ndarray: ... @@ -120,9 +118,9 @@ class LogisticRegressionCV(LogisticRegression, LinearClassifierMixin, BaseEstima l1_ratios: None | Sequence[float] = None, ) -> None: ... def fit( - self: LogisticRegressionCV_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> LogisticRegressionCV_Self: ... + ) -> Self: ... def score(self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None) -> float: ... diff --git a/stubs/sklearn/linear_model/_omp.pyi b/stubs/sklearn/linear_model/_omp.pyi index 7660854f..f7e517d8 100644 --- a/stubs/sklearn/linear_model/_omp.pyi +++ b/stubs/sklearn/linear_model/_omp.pyi @@ -2,7 +2,8 @@ import warnings from collections.abc import Iterable from math import sqrt as sqrt from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -17,9 +18,6 @@ from ..utils._param_validation import Hidden as Hidden, Interval as Interval, St from ..utils.parallel import Parallel as Parallel, delayed as delayed from ._base import LinearModel -OrthogonalMatchingPursuitCV_Self = TypeVar("OrthogonalMatchingPursuitCV_Self", bound=OrthogonalMatchingPursuitCV) -OrthogonalMatchingPursuit_Self = TypeVar("OrthogonalMatchingPursuit_Self", bound=OrthogonalMatchingPursuit) - # Author: Vlad Niculae # # License: BSD 3 clause @@ -69,7 +67,7 @@ class OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel): normalize: str | bool = "deprecated", precompute: Literal["auto"] | bool = "auto", ) -> None: ... - def fit(self: OrthogonalMatchingPursuit_Self, X: MatrixLike, y: MatrixLike | ArrayLike) -> OrthogonalMatchingPursuit_Self: ... + def fit(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> Self: ... class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): feature_names_in_: ndarray = ... @@ -92,4 +90,4 @@ class OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel): n_jobs: None | Int = None, verbose: int | bool = False, ) -> None: ... - def fit(self: OrthogonalMatchingPursuitCV_Self, X: MatrixLike, y: ArrayLike) -> OrthogonalMatchingPursuitCV_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... diff --git a/stubs/sklearn/linear_model/_passive_aggressive.pyi b/stubs/sklearn/linear_model/_passive_aggressive.pyi index 68fde643..8663d939 100644 --- a/stubs/sklearn/linear_model/_passive_aggressive.pyi +++ b/stubs/sklearn/linear_model/_passive_aggressive.pyi @@ -1,6 +1,7 @@ from collections.abc import Mapping from numbers import Real as Real -from typing import Callable, ClassVar, TypeVar +from typing import Callable, ClassVar +from typing_extensions import Self from numpy import ndarray from numpy.random import RandomState @@ -9,9 +10,6 @@ from .._typing import ArrayLike, Float, Int, MatrixLike from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ._stochastic_gradient import DEFAULT_EPSILON as DEFAULT_EPSILON, BaseSGDClassifier, BaseSGDRegressor -PassiveAggressiveClassifier_Self = TypeVar("PassiveAggressiveClassifier_Self", bound=PassiveAggressiveClassifier) -PassiveAggressiveRegressor_Self = TypeVar("PassiveAggressiveRegressor_Self", bound=PassiveAggressiveRegressor) - # Authors: Rob Zinkov, Mathieu Blondel # License: BSD 3 clause @@ -47,18 +45,18 @@ class PassiveAggressiveClassifier(BaseSGDClassifier): average: int | bool = False, ) -> None: ... def partial_fit( - self: PassiveAggressiveClassifier_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, classes: None | ArrayLike = None, - ) -> PassiveAggressiveClassifier_Self: ... + ) -> Self: ... def fit( - self: PassiveAggressiveClassifier_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, coef_init: None | MatrixLike = None, intercept_init: None | ArrayLike = None, - ) -> PassiveAggressiveClassifier_Self: ... + ) -> Self: ... class PassiveAggressiveRegressor(BaseSGDRegressor): t_: int = ... @@ -88,13 +86,11 @@ class PassiveAggressiveRegressor(BaseSGDRegressor): warm_start: bool = False, average: int | bool = False, ) -> None: ... - def partial_fit( - self: PassiveAggressiveRegressor_Self, X: MatrixLike | ArrayLike, y: ArrayLike - ) -> PassiveAggressiveRegressor_Self: ... + def partial_fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... def fit( - self: PassiveAggressiveRegressor_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, coef_init: None | ArrayLike = None, intercept_init: None | ArrayLike = None, - ) -> PassiveAggressiveRegressor_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/linear_model/_quantile.pyi b/stubs/sklearn/linear_model/_quantile.pyi index e76724cc..7c4f9c27 100644 --- a/stubs/sklearn/linear_model/_quantile.pyi +++ b/stubs/sklearn/linear_model/_quantile.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -13,8 +14,6 @@ from ..exceptions import ConvergenceWarning as ConvergenceWarning from ..utils._param_validation import Hidden as Hidden, Interval as Interval, StrOptions as StrOptions from ._base import LinearModel -QuantileRegressor_Self = TypeVar("QuantileRegressor_Self", bound=QuantileRegressor) - # Authors: David Dale # Christian Lorentzen # License: BSD 3 clause @@ -45,8 +44,8 @@ class QuantileRegressor(LinearModel, RegressorMixin, BaseEstimator): solver_options: None | dict = None, ) -> None: ... def fit( - self: QuantileRegressor_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> QuantileRegressor_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/linear_model/_ransac.pyi b/stubs/sklearn/linear_model/_ransac.pyi index 85384ca2..13c4dd1e 100644 --- a/stubs/sklearn/linear_model/_ransac.pyi +++ b/stubs/sklearn/linear_model/_ransac.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, TypeVar +from typing import Any, Callable, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -21,8 +22,6 @@ from ..utils.random import sample_without_replacement as sample_without_replacem from ..utils.validation import check_is_fitted as check_is_fitted, has_fit_parameter as has_fit_parameter from ._base import LinearRegression as LinearRegression -RANSACRegressor_Self = TypeVar("RANSACRegressor_Self", bound=RANSACRegressor) - # Author: Johannes Schönberger # # License: BSD 3 clause @@ -59,10 +58,10 @@ class RANSACRegressor(MetaEstimatorMixin, RegressorMixin, MultiOutputMixin, Base base_estimator: Any = "deprecated", ) -> None: ... def fit( - self: RANSACRegressor_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, - ) -> RANSACRegressor_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... def score(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> float: ... diff --git a/stubs/sklearn/linear_model/_ridge.pyi b/stubs/sklearn/linear_model/_ridge.pyi index 96c4cc74..e6748bf0 100644 --- a/stubs/sklearn/linear_model/_ridge.pyi +++ b/stubs/sklearn/linear_model/_ridge.pyi @@ -4,7 +4,8 @@ from abc import ABCMeta, abstractmethod from collections.abc import Iterable, Mapping from functools import partial as partial from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -37,13 +38,6 @@ from ..utils.validation import check_is_fitted as check_is_fitted from ._base import LinearClassifierMixin, LinearModel from ._sag import sag_solver as sag_solver -_BaseRidgeCV_Self = TypeVar("_BaseRidgeCV_Self", bound=_BaseRidgeCV) -_RidgeGCV_Self = TypeVar("_RidgeGCV_Self", bound=_RidgeGCV) -RidgeClassifier_Self = TypeVar("RidgeClassifier_Self", bound=RidgeClassifier) -RidgeClassifierCV_Self = TypeVar("RidgeClassifierCV_Self", bound=RidgeClassifierCV) -RidgeCV_Self = TypeVar("RidgeCV_Self", bound=RidgeCV) -Ridge_Self = TypeVar("Ridge_Self", bound=Ridge) - def ridge_regression( X: MatrixLike | LinearOperator, y: MatrixLike | ArrayLike, @@ -104,11 +98,11 @@ class Ridge(MultiOutputMixin, RegressorMixin, _BaseRidge): random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: Ridge_Self, + self, X: coo_matrix | MatrixLike, y: MatrixLike | ArrayLike, sample_weight: float | None | ArrayLike = None, - ) -> Ridge_Self: ... + ) -> Self: ... class _RidgeClassifierMixin(LinearClassifierMixin): def predict(self, X: MatrixLike) -> ndarray: ... @@ -138,11 +132,11 @@ class RidgeClassifier(_RidgeClassifierMixin, _BaseRidge): random_state: RandomState | None | Int = None, ) -> None: ... def fit( - self: RidgeClassifier_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: float | None | ArrayLike = None, - ) -> RidgeClassifier_Self: ... + ) -> Self: ... class _X_CenterStackOp(LinearOperator): def __init__(self, X, X_mean, sqrt_sw) -> None: ... @@ -172,11 +166,11 @@ class _RidgeGCV(LinearModel): alpha_per_target: bool = False, ) -> None: ... def fit( - self: _RidgeGCV_Self, + self, X: MatrixLike, y: MatrixLike | ArrayLike, sample_weight: float | None | ArrayLike = None, - ) -> _RidgeGCV_Self: ... + ) -> Self: ... class _BaseRidgeCV(LinearModel): _parameter_constraints: ClassVar[dict] = ... @@ -193,11 +187,11 @@ class _BaseRidgeCV(LinearModel): alpha_per_target: bool = False, ) -> None: ... def fit( - self: _BaseRidgeCV_Self, + self, X: ArrayLike | DataFrame, y: MatrixLike | ArrayLike, sample_weight: float | None | ArrayLike = None, - ) -> _BaseRidgeCV_Self | RidgeCV: ... + ) -> Self | RidgeCV: ... class RidgeCV(MultiOutputMixin, RegressorMixin, _BaseRidgeCV): feature_names_in_: ndarray = ... @@ -209,11 +203,11 @@ class RidgeCV(MultiOutputMixin, RegressorMixin, _BaseRidgeCV): cv_values_: ndarray = ... def fit( - self: RidgeCV_Self, + self, X: ArrayLike | DataFrame, y: MatrixLike | ArrayLike, sample_weight: float | None | ArrayLike = None, - ) -> RidgeCV_Self: ... + ) -> Self: ... class RidgeClassifierCV(_RidgeClassifierMixin, _BaseRidgeCV): feature_names_in_: ndarray = ... @@ -238,8 +232,8 @@ class RidgeClassifierCV(_RidgeClassifierMixin, _BaseRidgeCV): store_cv_values: bool = False, ) -> None: ... def fit( - self: RidgeClassifierCV_Self, + self, X: ArrayLike, y: ArrayLike, sample_weight: float | None | ArrayLike = None, - ) -> RidgeClassifierCV_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/linear_model/_stochastic_gradient.pyi b/stubs/sklearn/linear_model/_stochastic_gradient.pyi index 4e65604f..feacd685 100644 --- a/stubs/sklearn/linear_model/_stochastic_gradient.pyi +++ b/stubs/sklearn/linear_model/_stochastic_gradient.pyi @@ -2,7 +2,8 @@ import warnings from abc import ABCMeta, abstractmethod from collections.abc import Mapping from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -32,10 +33,6 @@ from ._sgd_fast import ( SquaredLoss as SquaredLoss, ) -BaseSGDClassifier_Self = TypeVar("BaseSGDClassifier_Self", bound=BaseSGDClassifier) -SGDOneClassSVM_Self = TypeVar("SGDOneClassSVM_Self", bound=SGDOneClassSVM) -BaseSGDRegressor_Self = TypeVar("BaseSGDRegressor_Self", bound=BaseSGDRegressor) - # Authors: Peter Prettenhofer (main author) # Mathieu Blondel (partial_fit support) # @@ -140,20 +137,20 @@ class BaseSGDClassifier(LinearClassifierMixin, BaseSGD, metaclass=ABCMeta): average: bool = False, ) -> None: ... def partial_fit( - self: BaseSGDClassifier_Self, + self, X: MatrixLike, y: ArrayLike, classes: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> BaseSGDClassifier_Self: ... + ) -> Self: ... def fit( - self: BaseSGDClassifier_Self, + self, X: MatrixLike, y: ArrayLike, coef_init: None | MatrixLike = None, intercept_init: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> BaseSGDClassifier_Self: ... + ) -> Self: ... class SGDClassifier(BaseSGDClassifier): feature_names_in_: ndarray = ... @@ -236,19 +233,19 @@ class BaseSGDRegressor(RegressorMixin, BaseSGD): average: bool = False, ) -> None: ... def partial_fit( - self: BaseSGDRegressor_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BaseSGDRegressor_Self: ... + ) -> Self: ... def fit( - self: BaseSGDRegressor_Self, + self, X: MatrixLike, y: ArrayLike, coef_init: None | ArrayLike = None, intercept_init: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> SGDRegressor | BaseSGDRegressor_Self: ... + ) -> SGDRegressor | Self: ... def predict(self, X: MatrixLike) -> ndarray: ... class SGDRegressor(BaseSGDRegressor): @@ -314,19 +311,19 @@ class SGDOneClassSVM(BaseSGD, OutlierMixin): average: int | bool = False, ) -> None: ... def partial_fit( - self: SGDOneClassSVM_Self, + self, X: MatrixLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> SGDOneClassSVM_Self: ... + ) -> Self: ... def fit( - self: SGDOneClassSVM_Self, + self, X: MatrixLike, y: Any = None, coef_init: None | MatrixLike = None, offset_init: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> SGDOneClassSVM_Self: ... + ) -> Self: ... def decision_function(self, X: MatrixLike) -> ndarray: ... def score_samples(self, X: MatrixLike) -> ndarray: ... def predict(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/linear_model/_theil_sen.pyi b/stubs/sklearn/linear_model/_theil_sen.pyi index 1792ea0c..1a2f648c 100644 --- a/stubs/sklearn/linear_model/_theil_sen.pyi +++ b/stubs/sklearn/linear_model/_theil_sen.pyi @@ -1,7 +1,8 @@ import warnings from itertools import combinations as combinations from numbers import Integral as Integral, Real as Real -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np from joblib import effective_n_jobs as effective_n_jobs @@ -19,8 +20,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.parallel import Parallel as Parallel, delayed as delayed from ._base import LinearModel -TheilSenRegressor_Self = TypeVar("TheilSenRegressor_Self", bound=TheilSenRegressor) - # Author: Florian Wilhelm # # License: BSD 3 clause @@ -51,4 +50,4 @@ class TheilSenRegressor(RegressorMixin, LinearModel): n_jobs: None | Int = None, verbose: bool = False, ) -> None: ... - def fit(self: TheilSenRegressor_Self, X: ArrayLike, y: ArrayLike) -> TheilSenRegressor_Self: ... + def fit(self, X: ArrayLike, y: ArrayLike) -> Self: ... diff --git a/stubs/sklearn/manifold/_isomap.pyi b/stubs/sklearn/manifold/_isomap.pyi index 199b0f4e..20d5cca8 100644 --- a/stubs/sklearn/manifold/_isomap.pyi +++ b/stubs/sklearn/manifold/_isomap.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,8 +19,6 @@ from ..preprocessing import KernelCenterer as KernelCenterer from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ..utils.validation import check_is_fitted as check_is_fitted -Isomap_Self = TypeVar("Isomap_Self", bound=Isomap) - # Author: Jake Vanderplas -- # License: BSD 3 clause (C) 2011 @@ -51,9 +50,9 @@ class Isomap(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): ) -> None: ... def reconstruction_error(self) -> float: ... def fit( - self: Isomap_Self, + self, X: ArrayLike | BallTree | NearestNeighbors | KDTree | csr_matrix, y: Any = None, - ) -> Isomap_Self: ... + ) -> Self: ... def fit_transform(self, X: BallTree | ArrayLike | KDTree, y: Any = None) -> ndarray: ... def transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/manifold/_locally_linear.pyi b/stubs/sklearn/manifold/_locally_linear.pyi index dc82a96e..138c1ca1 100644 --- a/stubs/sklearn/manifold/_locally_linear.pyi +++ b/stubs/sklearn/manifold/_locally_linear.pyi @@ -1,5 +1,6 @@ from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -17,8 +18,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.extmath import stable_cumsum as stable_cumsum from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted -LocallyLinearEmbedding_Self = TypeVar("LocallyLinearEmbedding_Self", bound=LocallyLinearEmbedding) - def barycenter_weights(X: MatrixLike, Y: MatrixLike, indices: MatrixLike, reg: Float = 1e-3) -> ndarray: ... def barycenter_kneighbors_graph( X: ArrayLike | NearestNeighbors, @@ -81,6 +80,6 @@ class LocallyLinearEmbedding( random_state: RandomState | None | Int = None, n_jobs: None | int = None, ) -> None: ... - def fit(self: LocallyLinearEmbedding_Self, X: MatrixLike, y: Any = None) -> LocallyLinearEmbedding_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def fit_transform(self, X: MatrixLike, y: Any = None) -> ndarray: ... def transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/manifold/_mds.pyi b/stubs/sklearn/manifold/_mds.pyi index 3b825741..e2dbabb9 100644 --- a/stubs/sklearn/manifold/_mds.pyi +++ b/stubs/sklearn/manifold/_mds.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import effective_n_jobs as effective_n_jobs @@ -15,8 +16,6 @@ from ..utils import check_array as check_array, check_random_state as check_rand from ..utils._param_validation import Hidden as Hidden, Interval as Interval, StrOptions as StrOptions from ..utils.parallel import Parallel as Parallel, delayed as delayed -MDS_Self = TypeVar("MDS_Self", bound=MDS) - def smacof( dissimilarities: MatrixLike, *, @@ -57,5 +56,5 @@ class MDS(BaseEstimator): dissimilarity: Literal["euclidean", "precomputed"] = "euclidean", normalized_stress: Literal["auto", "warn"] | bool = "warn", ) -> None: ... - def fit(self: MDS_Self, X: MatrixLike, y: Any = None, init: None | MatrixLike = None) -> MDS_Self: ... + def fit(self, X: MatrixLike, y: Any = None, init: None | MatrixLike = None) -> Self: ... def fit_transform(self, X: MatrixLike, y: Any = None, init: None | MatrixLike = None) -> ndarray: ... diff --git a/stubs/sklearn/manifold/_spectral_embedding.pyi b/stubs/sklearn/manifold/_spectral_embedding.pyi index e6fd0e94..7d5201ec 100644 --- a/stubs/sklearn/manifold/_spectral_embedding.pyi +++ b/stubs/sklearn/manifold/_spectral_embedding.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,8 +19,6 @@ from ..neighbors import NearestNeighbors as NearestNeighbors, kneighbors_graph a from ..utils import check_array as check_array, check_random_state as check_random_state, check_symmetric as check_symmetric from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions -SpectralEmbedding_Self = TypeVar("SpectralEmbedding_Self", bound=SpectralEmbedding) - def spectral_embedding( adjacency: coo_matrix | MatrixLike, *, @@ -54,5 +53,5 @@ class SpectralEmbedding(BaseEstimator): n_neighbors: None | Int = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: SpectralEmbedding_Self, X: MatrixLike | ArrayLike, y: Any = None) -> SpectralEmbedding_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def fit_transform(self, X: MatrixLike | ArrayLike, y: Any = None) -> ndarray: ... diff --git a/stubs/sklearn/mixture/_base.pyi b/stubs/sklearn/mixture/_base.pyi index c5c57bc0..e0dc5928 100644 --- a/stubs/sklearn/mixture/_base.pyi +++ b/stubs/sklearn/mixture/_base.pyi @@ -2,7 +2,8 @@ import warnings from abc import ABCMeta, abstractmethod as abstractmethod from numbers import Integral as Integral, Real as Real from time import time as time -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,8 +19,6 @@ from ..utils import check_random_state as check_random_state from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ..utils.validation import check_is_fitted as check_is_fitted -BaseMixture_Self = TypeVar("BaseMixture_Self", bound=BaseMixture) - # Author: Wei Xue # Modified by Thierry Guillemot # License: BSD 3 clause @@ -40,7 +39,7 @@ class BaseMixture(DensityMixin, BaseEstimator, metaclass=ABCMeta): verbose: int, verbose_interval: int, ) -> None: ... - def fit(self: BaseMixture_Self, X: MatrixLike, y: Any = None) -> BaseMixture_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def fit_predict(self, X: MatrixLike, y: Any = None) -> ndarray: ... def score_samples(self, X: MatrixLike) -> ndarray: ... def score(self, X: MatrixLike, y: Any = None) -> Float: ... diff --git a/stubs/sklearn/model_selection/_search.pyi b/stubs/sklearn/model_selection/_search.pyi index 2bcf1020..bd01bc25 100644 --- a/stubs/sklearn/model_selection/_search.pyi +++ b/stubs/sklearn/model_selection/_search.pyi @@ -8,6 +8,7 @@ from collections.abc import Iterable, Iterator, Mapping, Sequence from functools import partial as partial, reduce as reduce from itertools import product as product from typing import Any, Callable, ClassVar, Generic, TypeVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -28,7 +29,6 @@ from ..utils.validation import check_is_fitted as check_is_fitted, indexable as from . import BaseCrossValidator from ._split import check_cv as check_cv -BaseSearchCV_Self = TypeVar("BaseSearchCV_Self", bound=BaseSearchCV) BaseEstimatorT = TypeVar("BaseEstimatorT", bound=BaseEstimator, default=BaseEstimator, covariant=True) __all__ = ["GridSearchCV", "ParameterGrid", "ParameterSampler", "RandomizedSearchCV"] @@ -76,13 +76,13 @@ class BaseSearchCV(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta): def n_features_in_(self): ... def classes_(self): ... def fit( - self: BaseSearchCV_Self, + self, X: list[str] | MatrixLike, y: None | MatrixLike | ArrayLike = None, *, groups: None | ArrayLike = None, **fit_params, - ) -> BaseSearchCV_Self: ... + ) -> Self: ... class GridSearchCV(BaseSearchCV, Generic[BaseEstimatorT]): feature_names_in_: ndarray = ... diff --git a/stubs/sklearn/model_selection/_search_successive_halving.pyi b/stubs/sklearn/model_selection/_search_successive_halving.pyi index 8a3b9414..ab11a2ab 100644 --- a/stubs/sklearn/model_selection/_search_successive_halving.pyi +++ b/stubs/sklearn/model_selection/_search_successive_halving.pyi @@ -3,7 +3,8 @@ from collections.abc import Iterable, Iterator, Mapping, Sequence from copy import deepcopy as deepcopy from math import ceil as ceil, floor as floor, log as log from numbers import Integral as Integral -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,8 +19,6 @@ from . import BaseCrossValidator, ParameterGrid as ParameterGrid, ParameterSampl from ._search import BaseSearchCV from ._split import check_cv as check_cv -BaseSuccessiveHalving_Self = TypeVar("BaseSuccessiveHalving_Self", bound=BaseSuccessiveHalving) - __all__ = ["HalvingGridSearchCV", "HalvingRandomSearchCV"] class _SubsampleMetaSplitter: @@ -46,12 +45,12 @@ class BaseSuccessiveHalving(BaseSearchCV): aggressive_elimination: bool = False, ) -> None: ... def fit( - self: BaseSuccessiveHalving_Self, + self, X: MatrixLike, y: None | MatrixLike | ArrayLike = None, groups: None | ArrayLike = None, **fit_params, - ) -> BaseSuccessiveHalving_Self: ... + ) -> Self: ... class HalvingGridSearchCV(BaseSuccessiveHalving): feature_names_in_: ndarray = ... diff --git a/stubs/sklearn/multiclass.pyi b/stubs/sklearn/multiclass.pyi index bece5985..ba5213d9 100644 --- a/stubs/sklearn/multiclass.pyi +++ b/stubs/sklearn/multiclass.pyi @@ -2,7 +2,8 @@ import array import itertools import warnings from numbers import Integral as Integral, Real as Real -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -28,10 +29,6 @@ from .utils.multiclass import check_classification_targets as check_classificati from .utils.parallel import Parallel as Parallel, delayed as delayed from .utils.validation import check_is_fitted as check_is_fitted -OneVsRestClassifier_Self = TypeVar("OneVsRestClassifier_Self", bound=OneVsRestClassifier) -OneVsOneClassifier_Self = TypeVar("OneVsOneClassifier_Self", bound=OneVsOneClassifier) -OutputCodeClassifier_Self = TypeVar("OutputCodeClassifier_Self", bound=OutputCodeClassifier) - # Author: Mathieu Blondel # Author: Hamzeh Alsalhi <93hamsal@gmail.com> # @@ -60,16 +57,16 @@ class OneVsRestClassifier(MultiOutputMixin, ClassifierMixin, MetaEstimatorMixin, def __init__(self, estimator: BaseEstimator, *, n_jobs: None | Int = None, verbose: Int = 0) -> None: ... def fit( - self: OneVsRestClassifier_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, - ) -> OneVsRestClassifier_Self: ... + ) -> Self: ... def partial_fit( - self: OneVsRestClassifier_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, classes: None | ArrayLike = None, - ) -> OneVsRestClassifier_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... def decision_function(self, X: MatrixLike) -> ndarray: ... @@ -88,13 +85,13 @@ class OneVsOneClassifier(MetaEstimatorMixin, ClassifierMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, estimator: BaseEstimator, *, n_jobs: None | Int = None) -> None: ... - def fit(self: OneVsOneClassifier_Self, X: MatrixLike | ArrayLike, y: ArrayLike) -> OneVsOneClassifier_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... def partial_fit( - self: OneVsOneClassifier_Self, + self, X: MatrixLike, y: ArrayLike, classes: None | ArrayLike = None, - ) -> OneVsOneClassifier_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def decision_function(self, X: MatrixLike) -> ndarray: ... @property @@ -117,5 +114,5 @@ class OutputCodeClassifier(MetaEstimatorMixin, ClassifierMixin, BaseEstimator): random_state: RandomState | None | Int = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: OutputCodeClassifier_Self, X: MatrixLike | ArrayLike, y: ArrayLike) -> OutputCodeClassifier_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/multioutput.pyi b/stubs/sklearn/multioutput.pyi index e36c1633..35555221 100644 --- a/stubs/sklearn/multioutput.pyi +++ b/stubs/sklearn/multioutput.pyi @@ -1,7 +1,8 @@ from abc import ABCMeta, abstractmethod from collections.abc import Sequence from numbers import Integral as Integral -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -27,13 +28,6 @@ from .utils.multiclass import check_classification_targets as check_classificati from .utils.parallel import Parallel as Parallel, delayed as delayed from .utils.validation import check_is_fitted as check_is_fitted, has_fit_parameter as has_fit_parameter -MultiOutputClassifier_Self = TypeVar("MultiOutputClassifier_Self", bound=MultiOutputClassifier) -RegressorChain_Self = TypeVar("RegressorChain_Self", bound=RegressorChain) -_BaseChain_Self = TypeVar("_BaseChain_Self", bound=_BaseChain) -_MultiOutputEstimator_Self = TypeVar("_MultiOutputEstimator_Self", bound=_MultiOutputEstimator) -MultiOutputRegressor_Self = TypeVar("MultiOutputRegressor_Self", bound=MultiOutputRegressor) -ClassifierChain_Self = TypeVar("ClassifierChain_Self", bound=ClassifierChain) - __all__ = [ "MultiOutputRegressor", "MultiOutputClassifier", @@ -47,19 +41,19 @@ class _MultiOutputEstimator(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta @abstractmethod def __init__(self, estimator: RandomForestRegressor, *, n_jobs=None) -> None: ... def partial_fit( - self: _MultiOutputEstimator_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike, classes: Sequence[ArrayLike] | None = None, sample_weight: None | ArrayLike = None, - ) -> _MultiOutputEstimator_Self: ... + ) -> Self: ... def fit( - self: _MultiOutputEstimator_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike, sample_weight: None | ArrayLike = None, **fit_params, - ) -> _MultiOutputEstimator_Self | MultiOutputRegressor: ... + ) -> Self | MultiOutputRegressor: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray | spmatrix: ... class MultiOutputRegressor(RegressorMixin, _MultiOutputEstimator): @@ -69,11 +63,11 @@ class MultiOutputRegressor(RegressorMixin, _MultiOutputEstimator): def __init__(self, estimator: BaseEstimator | RandomForestRegressor, *, n_jobs: None | int = None) -> None: ... def partial_fit( - self: MultiOutputRegressor_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike, sample_weight: None | ArrayLike = None, - ) -> MultiOutputRegressor_Self: ... + ) -> Self: ... class MultiOutputClassifier(ClassifierMixin, _MultiOutputEstimator): feature_names_in_: ndarray = ... @@ -83,12 +77,12 @@ class MultiOutputClassifier(ClassifierMixin, _MultiOutputEstimator): def __init__(self, estimator: BaseEstimator, *, n_jobs: None | int = None) -> None: ... def fit( - self: MultiOutputClassifier_Self, + self, X: MatrixLike | ArrayLike, Y: MatrixLike, sample_weight: None | ArrayLike = None, **fit_params, - ) -> MultiOutputClassifier_Self: ... + ) -> Self: ... def predict_proba(self, X: MatrixLike) -> ndarray | list[ndarray]: ... def score(self, X: MatrixLike, y: MatrixLike) -> float: ... @@ -99,9 +93,7 @@ class _BaseChain(BaseEstimator, metaclass=ABCMeta): self, base_estimator: LogisticRegression, *, order=None, cv=None, random_state=None, verbose: bool = False ) -> None: ... @abstractmethod - def fit( - self: _BaseChain_Self, X: MatrixLike | ArrayLike, Y: MatrixLike, **fit_params - ) -> _BaseChain_Self | ClassifierChain: ... + def fit(self, X: MatrixLike | ArrayLike, Y: MatrixLike, **fit_params) -> Self | ClassifierChain: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... class ClassifierChain(MetaEstimatorMixin, ClassifierMixin, _BaseChain): @@ -111,7 +103,7 @@ class ClassifierChain(MetaEstimatorMixin, ClassifierMixin, _BaseChain): estimators_: list = ... classes_: list = ... - def fit(self: ClassifierChain_Self, X: MatrixLike | ArrayLike, Y: MatrixLike) -> ClassifierChain_Self: ... + def fit(self, X: MatrixLike | ArrayLike, Y: MatrixLike) -> Self: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... def decision_function(self, X: MatrixLike) -> ndarray: ... @@ -121,4 +113,4 @@ class RegressorChain(MetaEstimatorMixin, RegressorMixin, _BaseChain): order_: list = ... estimators_: list = ... - def fit(self: RegressorChain_Self, X: MatrixLike | ArrayLike, Y: MatrixLike, **fit_params) -> RegressorChain_Self: ... + def fit(self, X: MatrixLike | ArrayLike, Y: MatrixLike, **fit_params) -> Self: ... diff --git a/stubs/sklearn/naive_bayes.pyi b/stubs/sklearn/naive_bayes.pyi index 3264fca5..f1c020a8 100644 --- a/stubs/sklearn/naive_bayes.pyi +++ b/stubs/sklearn/naive_bayes.pyi @@ -1,7 +1,8 @@ import warnings from abc import ABCMeta, abstractmethod as abstractmethod from numbers import Integral as Integral, Real as Real -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,10 +15,6 @@ from .utils._param_validation import Hidden as Hidden, Interval as Interval, Str from .utils.extmath import safe_sparse_dot as safe_sparse_dot from .utils.validation import check_is_fitted as check_is_fitted, check_non_negative as check_non_negative -_BaseDiscreteNB_Self = TypeVar("_BaseDiscreteNB_Self", bound=_BaseDiscreteNB) -GaussianNB_Self = TypeVar("GaussianNB_Self", bound=GaussianNB) -CategoricalNB_Self = TypeVar("CategoricalNB_Self", bound=CategoricalNB) - # Author: Vincent Michel # Minor fixes by Fabian Pedregosa # Amit Aides @@ -56,18 +53,18 @@ class GaussianNB(_BaseNB): def __init__(self, *, priors: None | ArrayLike = None, var_smoothing: Float = 1e-9) -> None: ... def fit( - self: GaussianNB_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> GaussianNB_Self: ... + ) -> Self: ... def partial_fit( - self: GaussianNB_Self, + self, X: MatrixLike, y: ArrayLike, classes: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> GaussianNB_Self: ... + ) -> Self: ... class _BaseDiscreteNB(_BaseNB): _parameter_constraints: ClassVar[dict] = ... @@ -80,18 +77,18 @@ class _BaseDiscreteNB(_BaseNB): force_alpha: str = "warn", ) -> None: ... def partial_fit( - self: _BaseDiscreteNB_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, classes: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> MultinomialNB | _BaseDiscreteNB_Self: ... + ) -> MultinomialNB | Self: ... def fit( - self: _BaseDiscreteNB_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> _BaseDiscreteNB_Self | BernoulliNB | ComplementNB: ... + ) -> Self | BernoulliNB | ComplementNB: ... class MultinomialNB(_BaseDiscreteNB): feature_names_in_: ndarray = ... @@ -176,15 +173,15 @@ class CategoricalNB(_BaseDiscreteNB): min_categories: None | ArrayLike | Int = None, ) -> None: ... def fit( - self: CategoricalNB_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> CategoricalNB_Self: ... + ) -> Self: ... def partial_fit( - self: CategoricalNB_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, classes: None | ArrayLike = None, sample_weight: None | ArrayLike = None, - ) -> CategoricalNB_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/neighbors/_classification.pyi b/stubs/sklearn/neighbors/_classification.pyi index b63b12bc..bf4ca123 100644 --- a/stubs/sklearn/neighbors/_classification.pyi +++ b/stubs/sklearn/neighbors/_classification.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -11,9 +12,6 @@ from ..utils._param_validation import StrOptions as StrOptions from ..utils.extmath import weighted_mode as weighted_mode from ._base import KNeighborsMixin, NeighborsBase, RadiusNeighborsMixin -RadiusNeighborsClassifier_Self = TypeVar("RadiusNeighborsClassifier_Self", bound=RadiusNeighborsClassifier) -KNeighborsClassifier_Self = TypeVar("KNeighborsClassifier_Self", bound=KNeighborsClassifier) - class KNeighborsClassifier(KNeighborsMixin, ClassifierMixin, NeighborsBase): outputs_2d_: bool = ... n_samples_fit_: int = ... @@ -37,7 +35,7 @@ class KNeighborsClassifier(KNeighborsMixin, ClassifierMixin, NeighborsBase): metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: KNeighborsClassifier_Self, X: MatrixLike, y: MatrixLike | ArrayLike) -> KNeighborsClassifier_Self: ... + def fit(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray | list[ndarray]: ... @@ -66,6 +64,6 @@ class RadiusNeighborsClassifier(RadiusNeighborsMixin, ClassifierMixin, Neighbors metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: RadiusNeighborsClassifier_Self, X: MatrixLike, y: MatrixLike | ArrayLike) -> RadiusNeighborsClassifier_Self: ... + def fit(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/neighbors/_graph.pyi b/stubs/sklearn/neighbors/_graph.pyi index 7cb691b6..faa88bb7 100644 --- a/stubs/sklearn/neighbors/_graph.pyi +++ b/stubs/sklearn/neighbors/_graph.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self from numpy import ndarray from scipy.sparse import spmatrix @@ -11,9 +12,6 @@ from ._ball_tree import BallTree from ._base import KNeighborsMixin, NeighborsBase, RadiusNeighborsMixin from ._unsupervised import NearestNeighbors -RadiusNeighborsTransformer_Self = TypeVar("RadiusNeighborsTransformer_Self", bound=RadiusNeighborsTransformer) -KNeighborsTransformer_Self = TypeVar("KNeighborsTransformer_Self", bound=KNeighborsTransformer) - def kneighbors_graph( X: MatrixLike | BallTree | NearestNeighbors, n_neighbors: Int, @@ -58,7 +56,7 @@ class KNeighborsTransformer(ClassNamePrefixFeaturesOutMixin, KNeighborsMixin, Tr metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: KNeighborsTransformer_Self, X: MatrixLike, y: Any = None) -> KNeighborsTransformer_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike) -> spmatrix: ... def fit_transform(self, X: MatrixLike, y: Any = None) -> spmatrix: ... @@ -88,6 +86,6 @@ class RadiusNeighborsTransformer( metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: RadiusNeighborsTransformer_Self, X: MatrixLike, y: Any = None) -> RadiusNeighborsTransformer_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike): ... def fit_transform(self, X: MatrixLike, y: Any = None): ... diff --git a/stubs/sklearn/neighbors/_kde.pyi b/stubs/sklearn/neighbors/_kde.pyi index 35b7ea6f..6f34fd3a 100644 --- a/stubs/sklearn/neighbors/_kde.pyi +++ b/stubs/sklearn/neighbors/_kde.pyi @@ -1,6 +1,7 @@ import itertools from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,8 +19,6 @@ from ._ball_tree import DTYPE as DTYPE, BallTree as BallTree from ._binary_tree import BinaryTree from ._kd_tree import KDTree as KDTree -KernelDensity_Self = TypeVar("KernelDensity_Self", bound=KernelDensity) - # Author: Jake Vanderplas VALID_KERNELS: list = ... @@ -50,11 +49,11 @@ class KernelDensity(BaseEstimator): metric_params: None | dict = None, ) -> None: ... def fit( - self: KernelDensity_Self, + self, X: MatrixLike, y=None, sample_weight: None | ArrayLike = None, - ) -> KernelDensity_Self: ... + ) -> Self: ... def score_samples(self, X: MatrixLike) -> ndarray: ... def score(self, X: MatrixLike, y=None) -> Float: ... def sample(self, n_samples: Int = 1, random_state: RandomState | None | Int = None) -> ndarray: ... diff --git a/stubs/sklearn/neighbors/_lof.pyi b/stubs/sklearn/neighbors/_lof.pyi index 0f7546a5..a3ba8d9f 100644 --- a/stubs/sklearn/neighbors/_lof.pyi +++ b/stubs/sklearn/neighbors/_lof.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -13,8 +14,6 @@ from ..utils.metaestimators import available_if as available_if from ..utils.validation import check_is_fitted as check_is_fitted from ._base import KNeighborsMixin, NeighborsBase -LocalOutlierFactor_Self = TypeVar("LocalOutlierFactor_Self", bound=LocalOutlierFactor) - # Authors: Nicolas Goix # Alexandre Gramfort # License: BSD 3 clause @@ -47,7 +46,7 @@ class LocalOutlierFactor(KNeighborsMixin, OutlierMixin, NeighborsBase): n_jobs: None | Int = None, ) -> None: ... def fit_predict(self, X: MatrixLike | ArrayLike, y: Any = None) -> ndarray: ... - def fit(self: LocalOutlierFactor_Self, X: MatrixLike, y: Any = None) -> LocalOutlierFactor_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... def predict(self, X: None | MatrixLike | ArrayLike = None) -> ndarray: ... def decision_function(self, X: MatrixLike | ArrayLike) -> ndarray: ... def score_samples(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/neighbors/_nca.pyi b/stubs/sklearn/neighbors/_nca.pyi index 5c17b7a9..88418416 100644 --- a/stubs/sklearn/neighbors/_nca.pyi +++ b/stubs/sklearn/neighbors/_nca.pyi @@ -1,7 +1,8 @@ import sys import time from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self from warnings import warn as warn import numpy as np @@ -21,8 +22,6 @@ from ..utils.multiclass import check_classification_targets as check_classificat from ..utils.random import check_random_state as check_random_state from ..utils.validation import check_array as check_array, check_is_fitted as check_is_fitted -NeighborhoodComponentsAnalysis_Self = TypeVar("NeighborhoodComponentsAnalysis_Self", bound=NeighborhoodComponentsAnalysis) - class NeighborhoodComponentsAnalysis(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): feature_names_in_: ndarray = ... random_state_: RandomState = ... @@ -44,5 +43,5 @@ class NeighborhoodComponentsAnalysis(ClassNamePrefixFeaturesOutMixin, Transforme verbose: Int = 0, random_state: None | RandomState | int = None, ) -> None: ... - def fit(self: NeighborhoodComponentsAnalysis_Self, X: MatrixLike, y: ArrayLike) -> NeighborhoodComponentsAnalysis_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/neighbors/_nearest_centroid.pyi b/stubs/sklearn/neighbors/_nearest_centroid.pyi index 0b76adb1..70c8339f 100644 --- a/stubs/sklearn/neighbors/_nearest_centroid.pyi +++ b/stubs/sklearn/neighbors/_nearest_centroid.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Real as Real -from typing import Callable, ClassVar, TypeVar +from typing import Callable, ClassVar +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -15,8 +16,6 @@ from ..utils.multiclass import check_classification_targets as check_classificat from ..utils.sparsefuncs import csc_median_axis_0 as csc_median_axis_0 from ..utils.validation import check_is_fitted as check_is_fitted -NearestCentroid_Self = TypeVar("NearestCentroid_Self", bound=NearestCentroid) - # Author: Robert Layton # Olivier Grisel # @@ -31,5 +30,5 @@ class NearestCentroid(ClassifierMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, metric: str | Callable = "euclidean", *, shrink_threshold: None | Float = None) -> None: ... - def fit(self: NearestCentroid_Self, X: MatrixLike | ArrayLike, y: ArrayLike) -> NearestCentroid_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/neighbors/_regression.pyi b/stubs/sklearn/neighbors/_regression.pyi index c614f623..c14c6009 100644 --- a/stubs/sklearn/neighbors/_regression.pyi +++ b/stubs/sklearn/neighbors/_regression.pyi @@ -1,5 +1,6 @@ import warnings -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -9,9 +10,6 @@ from ..base import RegressorMixin from ..utils._param_validation import StrOptions as StrOptions from ._base import KNeighborsMixin, NeighborsBase, RadiusNeighborsMixin -KNeighborsRegressor_Self = TypeVar("KNeighborsRegressor_Self", bound=KNeighborsRegressor) -RadiusNeighborsRegressor_Self = TypeVar("RadiusNeighborsRegressor_Self", bound=RadiusNeighborsRegressor) - # Authors: Jake Vanderplas # Fabian Pedregosa # Alexandre Gramfort @@ -43,7 +41,7 @@ class KNeighborsRegressor(KNeighborsMixin, RegressorMixin, NeighborsBase): metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: KNeighborsRegressor_Self, X: MatrixLike, y: MatrixLike | ArrayLike) -> KNeighborsRegressor_Self: ... + def fit(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... class RadiusNeighborsRegressor(RadiusNeighborsMixin, RegressorMixin, NeighborsBase): @@ -67,5 +65,5 @@ class RadiusNeighborsRegressor(RadiusNeighborsMixin, RegressorMixin, NeighborsBa metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: RadiusNeighborsRegressor_Self, X: MatrixLike, y: MatrixLike | ArrayLike) -> RadiusNeighborsRegressor_Self: ... + def fit(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/neighbors/_unsupervised.pyi b/stubs/sklearn/neighbors/_unsupervised.pyi index 21081306..f994e989 100644 --- a/stubs/sklearn/neighbors/_unsupervised.pyi +++ b/stubs/sklearn/neighbors/_unsupervised.pyi @@ -1,12 +1,11 @@ -from typing import Any, Callable, Literal, TypeVar +from typing import Any, Callable, Literal +from typing_extensions import Self from numpy import ndarray from .._typing import Float, Int, MatrixLike from ._base import KNeighborsMixin, NeighborsBase, RadiusNeighborsMixin -NearestNeighbors_Self = TypeVar("NearestNeighbors_Self", bound=NearestNeighbors) - class NearestNeighbors(KNeighborsMixin, RadiusNeighborsMixin, NeighborsBase): n_samples_fit_: int = ... feature_names_in_: ndarray = ... @@ -26,4 +25,4 @@ class NearestNeighbors(KNeighborsMixin, RadiusNeighborsMixin, NeighborsBase): metric_params: None | dict = None, n_jobs: None | Int = None, ) -> None: ... - def fit(self: NearestNeighbors_Self, X: MatrixLike, y: Any = None) -> NearestNeighbors_Self: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self: ... diff --git a/stubs/sklearn/neural_network/_multilayer_perceptron.pyi b/stubs/sklearn/neural_network/_multilayer_perceptron.pyi index 45bc641a..d2f80f66 100644 --- a/stubs/sklearn/neural_network/_multilayer_perceptron.pyi +++ b/stubs/sklearn/neural_network/_multilayer_perceptron.pyi @@ -2,7 +2,8 @@ import warnings from abc import ABCMeta, abstractmethod from itertools import chain as chain from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.optimize @@ -24,10 +25,6 @@ from ..utils.validation import check_is_fitted as check_is_fitted from ._base import ACTIVATIONS as ACTIVATIONS, DERIVATIVES as DERIVATIVES, LOSS_FUNCTIONS as LOSS_FUNCTIONS from ._stochastic_optimizers import AdamOptimizer as AdamOptimizer, SGDOptimizer as SGDOptimizer -BaseMultilayerPerceptron_Self = TypeVar("BaseMultilayerPerceptron_Self", bound=BaseMultilayerPerceptron) -MLPRegressor_Self = TypeVar("MLPRegressor_Self", bound=MLPRegressor) -MLPClassifier_Self = TypeVar("MLPClassifier_Self", bound=MLPClassifier) - _STOCHASTIC_SOLVERS: list = ... class BaseMultilayerPerceptron(BaseEstimator, metaclass=ABCMeta): @@ -61,7 +58,7 @@ class BaseMultilayerPerceptron(BaseEstimator, metaclass=ABCMeta): n_iter_no_change: int, max_fun: int, ) -> None: ... - def fit(self: BaseMultilayerPerceptron_Self, X: MatrixLike, y: MatrixLike | ArrayLike) -> BaseMultilayerPerceptron_Self: ... + def fit(self, X: MatrixLike, y: MatrixLike | ArrayLike) -> Self: ... class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): out_activation_: str = ... @@ -109,11 +106,11 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron): ) -> None: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def partial_fit( - self: MLPClassifier_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, classes: None | ArrayLike = None, - ) -> MLPClassifier_Self: ... + ) -> Self: ... def predict_log_proba(self, X: ArrayLike) -> ndarray: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... @@ -161,4 +158,4 @@ class MLPRegressor(RegressorMixin, BaseMultilayerPerceptron): max_fun: Int = 15000, ) -> None: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... - def partial_fit(self: MLPRegressor_Self, X: MatrixLike | ArrayLike, y: ArrayLike) -> MLPRegressor_Self: ... + def partial_fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... diff --git a/stubs/sklearn/neural_network/_rbm.pyi b/stubs/sklearn/neural_network/_rbm.pyi index 53336bb6..939073cb 100644 --- a/stubs/sklearn/neural_network/_rbm.pyi +++ b/stubs/sklearn/neural_network/_rbm.pyi @@ -1,6 +1,7 @@ import time from numbers import Integral as Integral, Real as Real -from typing import ClassVar, TypeVar +from typing import ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -15,8 +16,6 @@ from ..utils._param_validation import Interval as Interval from ..utils.extmath import log_logistic as log_logistic, safe_sparse_dot as safe_sparse_dot from ..utils.validation import check_is_fitted as check_is_fitted -BernoulliRBM_Self = TypeVar("BernoulliRBM_Self", bound=BernoulliRBM) - # Authors: Yann N. Dauphin # Vlad Niculae # Gabriel Synnaeve @@ -45,10 +44,10 @@ class BernoulliRBM(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstima ) -> None: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray: ... def gibbs(self, v: ArrayLike) -> ndarray: ... - def partial_fit(self: BernoulliRBM_Self, X: ArrayLike, y: None | MatrixLike | ArrayLike = None) -> BernoulliRBM_Self: ... + def partial_fit(self, X: ArrayLike, y: None | MatrixLike | ArrayLike = None) -> Self: ... def score_samples(self, X: MatrixLike | ArrayLike) -> ndarray: ... def fit( - self: BernoulliRBM_Self, + self, X: MatrixLike | ArrayLike, y: None | MatrixLike | ArrayLike = None, - ) -> BernoulliRBM_Self: ... + ) -> Self: ... diff --git a/stubs/sklearn/pipeline.pyi b/stubs/sklearn/pipeline.pyi index f616bc40..d4f2c5b8 100644 --- a/stubs/sklearn/pipeline.pyi +++ b/stubs/sklearn/pipeline.pyi @@ -1,7 +1,8 @@ from collections import defaultdict as defaultdict from collections.abc import Iterable, Sequence from itertools import islice as islice -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from joblib import Memory @@ -21,9 +22,6 @@ from .utils.metaestimators import _BaseComposition, available_if as available_if from .utils.parallel import Parallel as Parallel, delayed as delayed from .utils.validation import check_is_fitted as check_is_fitted, check_memory as check_memory -FeatureUnion_Self = TypeVar("FeatureUnion_Self", bound=FeatureUnion) -Pipeline_Self = TypeVar("Pipeline_Self", bound=Pipeline) - __all__ = ["Pipeline", "FeatureUnion", "make_pipeline", "make_union"] class Pipeline(_BaseComposition): @@ -33,17 +31,17 @@ class Pipeline(_BaseComposition): def __init__(self, steps: Sequence[tuple], *, memory: None | Memory | str = None, verbose: bool = False) -> None: ... def set_output(self, *, transform: None | Literal["default", "pandas"] = None) -> BaseEstimator: ... def get_params(self, deep: bool = True) -> dict[str, Any]: ... - def set_params(self: Pipeline_Self, **kwargs) -> Pipeline_Self: ... + def set_params(self, **kwargs) -> Self: ... def __len__(self) -> int: ... def __getitem__(self, ind: slice | int): ... @property def named_steps(self) -> Bunch: ... def fit( - self: Pipeline_Self, + self, X: list[str] | ndarray | Iterable | DataFrame, y: list[Int] | list[int] | Iterable | None | Series | ndarray = None, **fit_params, - ) -> Pipeline_Self: ... + ) -> Self: ... def fit_transform(self, X: Iterable, y: Iterable | Series | None | ndarray = None, **fit_params) -> ndarray: ... def predict(self, X: list[str] | ndarray | Iterable | DataFrame, **predict_params) -> ndarray | tuple[ndarray, ndarray]: ... def fit_predict(self, X: Iterable, y: Iterable | None = None, **fit_params) -> ndarray: ... @@ -85,9 +83,9 @@ class FeatureUnion(TransformerMixin, _BaseComposition): @property def named_transformers(self) -> Bunch: ... def get_params(self, deep: bool = True) -> dict[str, Any]: ... - def set_params(self: FeatureUnion_Self, **kwargs) -> FeatureUnion_Self: ... + def set_params(self, **kwargs) -> Self: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... - def fit(self: FeatureUnion_Self, X: Iterable | ArrayLike, y: None | MatrixLike = None, **fit_params) -> FeatureUnion_Self: ... + def fit(self, X: Iterable | ArrayLike, y: None | MatrixLike = None, **fit_params) -> Self: ... def fit_transform( self, X: Iterable | ArrayLike | DataFrame, y: Series | None | MatrixLike = None, **fit_params ) -> ndarray | spmatrix: ... diff --git a/stubs/sklearn/preprocessing/_data.pyi b/stubs/sklearn/preprocessing/_data.pyi index 3f589d70..d13c284a 100644 --- a/stubs/sklearn/preprocessing/_data.pyi +++ b/stubs/sklearn/preprocessing/_data.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar, overload +from typing import Any, ClassVar, Literal, overload +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -33,16 +34,6 @@ from ..utils.validation import ( ) from ._encoders import OneHotEncoder -RobustScaler_Self = TypeVar("RobustScaler_Self", bound=RobustScaler) -KernelCenterer_Self = TypeVar("KernelCenterer_Self", bound=KernelCenterer) -Binarizer_Self = TypeVar("Binarizer_Self", bound=Binarizer) -QuantileTransformer_Self = TypeVar("QuantileTransformer_Self", bound=QuantileTransformer) -MaxAbsScaler_Self = TypeVar("MaxAbsScaler_Self", bound=MaxAbsScaler) -StandardScaler_Self = TypeVar("StandardScaler_Self", bound=StandardScaler) -MinMaxScaler_Self = TypeVar("MinMaxScaler_Self", bound=MinMaxScaler) -Normalizer_Self = TypeVar("Normalizer_Self", bound=Normalizer) -PowerTransformer_Self = TypeVar("PowerTransformer_Self", bound=PowerTransformer) - # Authors: Alexandre Gramfort # Mathieu Blondel # Olivier Grisel @@ -104,8 +95,8 @@ class MinMaxScaler(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): copy: bool = True, clip: bool = False, ) -> None: ... - def fit(self: MinMaxScaler_Self, X: MatrixLike, y: Series | None | ndarray = None) -> MinMaxScaler_Self: ... - def partial_fit(self: MinMaxScaler_Self, X: MatrixLike, y: Series | None | ndarray = None) -> MinMaxScaler_Self: ... + def fit(self, X: MatrixLike, y: Series | None | ndarray = None) -> Self: ... + def partial_fit(self, X: MatrixLike, y: Series | None | ndarray = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... @@ -129,17 +120,17 @@ class StandardScaler(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): def __init__(self, *, copy: bool = True, with_mean: bool = True, with_std: bool = True) -> None: ... def fit( - self: StandardScaler_Self, + self, X: MatrixLike | ArrayLike, y: Series | None | ndarray | list[int] = None, sample_weight: None | ArrayLike = None, - ) -> StandardScaler_Self: ... + ) -> Self: ... def partial_fit( - self: StandardScaler_Self, + self, X: MatrixLike | ArrayLike, y: Series | None | ndarray | list[int] = None, sample_weight: None | ArrayLike = None, - ) -> StandardScaler_Self: ... + ) -> Self: ... @overload def transform(self, X: spmatrix, copy: None | bool = None) -> spmatrix: ... @overload @@ -161,8 +152,8 @@ class MaxAbsScaler(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, copy: bool = True) -> None: ... - def fit(self: MaxAbsScaler_Self, X: MatrixLike | ArrayLike, y=None) -> MaxAbsScaler_Self: ... - def partial_fit(self: MaxAbsScaler_Self, X: MatrixLike | ArrayLike, y=None) -> MaxAbsScaler_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y=None) -> Self: ... + def partial_fit(self, X: MatrixLike | ArrayLike, y=None) -> Self: ... @overload def transform(self, X: spmatrix) -> spmatrix: ... @overload @@ -193,7 +184,7 @@ class RobustScaler(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): copy: bool = True, unit_variance: bool = False, ) -> None: ... - def fit(self: RobustScaler_Self, X: MatrixLike | ArrayLike, y: Any = None) -> RobustScaler_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... @overload def transform(self, X: spmatrix) -> spmatrix: ... @overload @@ -289,7 +280,7 @@ class Normalizer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, norm: Literal["l1", "l2", "max"] = "l2", *, copy: bool = True) -> None: ... - def fit(self: Normalizer_Self, X: MatrixLike | ArrayLike, y: Any = None) -> Normalizer_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... @overload def transform(self, X: spmatrix, copy: None | bool = None) -> spmatrix: ... @overload @@ -305,7 +296,7 @@ class Binarizer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, threshold: Float = 0.0, copy: bool = True) -> None: ... - def fit(self: Binarizer_Self, X: MatrixLike | ArrayLike, y=None) -> Binarizer_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y=None) -> Self: ... @overload def transform(self, X: spmatrix, copy: None | bool = None) -> spmatrix: ... @overload @@ -319,7 +310,7 @@ class KernelCenterer(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEsti K_fit_rows_: ndarray = ... def __init__(self) -> None: ... - def fit(self: KernelCenterer_Self, K: MatrixLike, y=None) -> KernelCenterer_Self: ... + def fit(self, K: MatrixLike, y=None) -> Self: ... def transform(self, K: MatrixLike, copy: bool = True) -> ndarray: ... @overload @@ -348,10 +339,10 @@ class QuantileTransformer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator) copy: bool = True, ) -> None: ... def fit( - self: QuantileTransformer_Self, + self, X: MatrixLike | ArrayLike, y: Series | None = None, - ) -> QuantileTransformer_Self: ... + ) -> Self: ... @overload def transform(self, X: spmatrix) -> spmatrix: ... @overload @@ -413,7 +404,7 @@ class PowerTransformer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): standardize: bool = True, copy: bool = True, ) -> None: ... - def fit(self: PowerTransformer_Self, X: MatrixLike, y=None) -> PowerTransformer_Self: ... + def fit(self, X: MatrixLike, y=None) -> Self: ... def fit_transform(self, X: MatrixLike, y: Any = None) -> ndarray: ... def transform(self, X: MatrixLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/preprocessing/_discretization.pyi b/stubs/sklearn/preprocessing/_discretization.pyi index d73ca39d..e7144c8e 100644 --- a/stubs/sklearn/preprocessing/_discretization.pyi +++ b/stubs/sklearn/preprocessing/_discretization.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -19,8 +20,6 @@ from ..utils.validation import ( ) from . import OneHotEncoder as OneHotEncoder -KBinsDiscretizer_Self = TypeVar("KBinsDiscretizer_Self", bound=KBinsDiscretizer) - # Author: Henry Lin # Tom Dupré la Tour @@ -44,7 +43,7 @@ class KBinsDiscretizer(TransformerMixin, BaseEstimator): subsample: int | None | Literal["warn"] = "warn", random_state: RandomState | None | Int = None, ) -> None: ... - def fit(self: KBinsDiscretizer_Self, X: MatrixLike, y: Series | None | ndarray = None) -> KBinsDiscretizer_Self: ... + def fit(self, X: MatrixLike, y: Series | None | ndarray = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray | spmatrix: ... def inverse_transform(self, Xt: MatrixLike) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/preprocessing/_encoders.pyi b/stubs/sklearn/preprocessing/_encoders.pyi index 00c24991..e1d0d994 100644 --- a/stubs/sklearn/preprocessing/_encoders.pyi +++ b/stubs/sklearn/preprocessing/_encoders.pyi @@ -2,7 +2,8 @@ import numbers import warnings from collections.abc import Sequence from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -15,9 +16,6 @@ from ..utils import check_array as check_array, is_scalar_nan as is_scalar_nan from ..utils._param_validation import Hidden as Hidden, Interval as Interval, StrOptions as StrOptions from ..utils.validation import check_is_fitted as check_is_fitted -OrdinalEncoder_Self = TypeVar("OrdinalEncoder_Self", bound=OrdinalEncoder) -OneHotEncoder_Self = TypeVar("OneHotEncoder_Self", bound=OneHotEncoder) - # Authors: Andreas Mueller # Joris Van den Bossche # License: BSD 3 clause @@ -49,10 +47,10 @@ class OneHotEncoder(_BaseEncoder): @property def infrequent_categories_(self) -> list[ndarray]: ... def fit( - self: OneHotEncoder_Self, + self, X: MatrixLike, y: Series | None | ndarray | list[int] = None, - ) -> OneHotEncoder_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike) -> ndarray | spmatrix: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... @@ -73,6 +71,6 @@ class OrdinalEncoder(OneToOneFeatureMixin, _BaseEncoder): unknown_value: float | None = None, encoded_missing_value: float = ..., ) -> None: ... - def fit(self: OrdinalEncoder_Self, X: MatrixLike, y: Series | None = None) -> OrdinalEncoder_Self: ... + def fit(self, X: MatrixLike, y: Series | None = None) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/preprocessing/_function_transformer.pyi b/stubs/sklearn/preprocessing/_function_transformer.pyi index 51080f02..3b6abb89 100644 --- a/stubs/sklearn/preprocessing/_function_transformer.pyi +++ b/stubs/sklearn/preprocessing/_function_transformer.pyi @@ -1,5 +1,6 @@ import warnings -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray, ufunc @@ -11,8 +12,6 @@ from ..utils._param_validation import StrOptions as StrOptions from ..utils.metaestimators import available_if as available_if from ..utils.validation import check_array as check_array -FunctionTransformer_Self = TypeVar("FunctionTransformer_Self", bound=FunctionTransformer) - class FunctionTransformer(TransformerMixin, BaseEstimator): feature_names_in_: ndarray = ... n_features_in_: int = ... @@ -31,7 +30,7 @@ class FunctionTransformer(TransformerMixin, BaseEstimator): kw_args: None | dict = None, inv_kw_args: None | dict = None, ) -> None: ... - def fit(self: FunctionTransformer_Self, X: list[str] | MatrixLike, y: Any = None) -> FunctionTransformer_Self: ... + def fit(self, X: list[str] | MatrixLike, y: Any = None) -> Self: ... def transform(self, X: list[str] | MatrixLike) -> ndarray | DataFrame | list[dict[str, int]]: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... diff --git a/stubs/sklearn/preprocessing/_label.pyi b/stubs/sklearn/preprocessing/_label.pyi index fc63621f..b4ffe2ad 100644 --- a/stubs/sklearn/preprocessing/_label.pyi +++ b/stubs/sklearn/preprocessing/_label.pyi @@ -4,7 +4,8 @@ import warnings from collections import defaultdict as defaultdict from collections.abc import Iterable from numbers import Integral as Integral -from typing import Any, ClassVar, TypeVar +from typing import Any, ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -19,10 +20,6 @@ from ..utils.multiclass import type_of_target as type_of_target, unique_labels a from ..utils.sparsefuncs import min_max_axis as min_max_axis from ..utils.validation import check_array as check_array, check_is_fitted as check_is_fitted -MultiLabelBinarizer_Self = TypeVar("MultiLabelBinarizer_Self", bound=MultiLabelBinarizer) -LabelEncoder_Self = TypeVar("LabelEncoder_Self", bound=LabelEncoder) -LabelBinarizer_Self = TypeVar("LabelBinarizer_Self", bound=LabelBinarizer) - # Authors: Alexandre Gramfort # Mathieu Blondel # Olivier Grisel @@ -41,7 +38,7 @@ __all__ = [ class LabelEncoder(TransformerMixin, BaseEstimator): classes_: ndarray = ... - def fit(self: LabelEncoder_Self, y: ArrayLike) -> LabelEncoder_Self: ... + def fit(self, y: ArrayLike) -> Self: ... def fit_transform(self, y: ArrayLike) -> ArrayLike: ... def transform(self, y: ArrayLike) -> ArrayLike: ... def inverse_transform(self, y: ArrayLike) -> ndarray: ... @@ -54,7 +51,7 @@ class LabelBinarizer(TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, neg_label: Int = 0, pos_label: Int = 1, sparse_output: bool = False) -> None: ... - def fit(self: LabelBinarizer_Self, y: MatrixLike | ArrayLike) -> LabelBinarizer_Self: ... + def fit(self, y: MatrixLike | ArrayLike) -> Self: ... def fit_transform(self, y: MatrixLike | ArrayLike) -> ndarray | spmatrix: ... def transform(self, y: MatrixLike | ArrayLike) -> ndarray | spmatrix: ... def inverse_transform(self, Y: MatrixLike, threshold: None | Float = None) -> ndarray | spmatrix: ... @@ -69,7 +66,7 @@ class MultiLabelBinarizer(TransformerMixin, BaseEstimator): _parameter_constraints: ClassVar[dict] = ... def __init__(self, *, classes: None | ArrayLike = None, sparse_output: bool = False) -> None: ... - def fit(self: MultiLabelBinarizer_Self, y: Iterable[Iterable] | list[range]) -> MultiLabelBinarizer_Self: ... + def fit(self, y: Iterable[Iterable] | list[range]) -> Self: ... def fit_transform(self, y: Iterable[Iterable]) -> ndarray | spmatrix: ... def transform(self, y: list[list[Any | Int]] | Iterable[Iterable]) -> csr_matrix | ndarray: ... def inverse_transform(self, yt: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/preprocessing/_polynomial.pyi b/stubs/sklearn/preprocessing/_polynomial.pyi index 60979cbf..c67c1463 100644 --- a/stubs/sklearn/preprocessing/_polynomial.pyi +++ b/stubs/sklearn/preprocessing/_polynomial.pyi @@ -1,7 +1,8 @@ import collections from itertools import chain as chain, combinations as combinations, combinations_with_replacement as combinations_w_r from numbers import Integral as Integral -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -17,9 +18,6 @@ from ..utils import check_array as check_array from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted -SplineTransformer_Self = TypeVar("SplineTransformer_Self", bound=SplineTransformer) -PolynomialFeatures_Self = TypeVar("PolynomialFeatures_Self", bound=PolynomialFeatures) - __all__ = [ "PolynomialFeatures", "SplineTransformer", @@ -43,7 +41,7 @@ class PolynomialFeatures(TransformerMixin, BaseEstimator): @property def powers_(self) -> ndarray: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... - def fit(self: PolynomialFeatures_Self, X: MatrixLike | ArrayLike, y: Any = None) -> PolynomialFeatures_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: Any = None) -> Self: ... def transform(self, X: MatrixLike | ArrayLike) -> ndarray | spmatrix: ... # TODO: @@ -69,9 +67,9 @@ class SplineTransformer(TransformerMixin, BaseEstimator): ) -> None: ... def get_feature_names_out(self, input_features: None | ArrayLike = None) -> ndarray: ... def fit( - self: SplineTransformer_Self, + self, X: MatrixLike, y: Series | None | ndarray = None, sample_weight: None | ArrayLike = None, - ) -> SplineTransformer_Self: ... + ) -> Self: ... def transform(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/random_projection.pyi b/stubs/sklearn/random_projection.pyi index e46f7637..371ea481 100644 --- a/stubs/sklearn/random_projection.pyi +++ b/stubs/sklearn/random_projection.pyi @@ -2,7 +2,8 @@ import warnings from abc import ABCMeta, abstractmethod from collections.abc import Sequence from numbers import Integral as Integral, Real as Real -from typing import Any, ClassVar, Literal, TypeVar +from typing import Any, ClassVar, Literal +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -20,8 +21,6 @@ from .utils.extmath import safe_sparse_dot as safe_sparse_dot from .utils.random import sample_without_replacement as sample_without_replacement from .utils.validation import check_array as check_array, check_is_fitted as check_is_fitted -BaseRandomProjection_Self = TypeVar("BaseRandomProjection_Self", bound=BaseRandomProjection) - # Authors: Olivier Grisel , # Arnaud Joly # License: BSD 3 clause @@ -48,9 +47,7 @@ class BaseRandomProjection(TransformerMixin, BaseEstimator, ClassNamePrefixFeatu compute_inverse_components: bool = False, random_state=None, ) -> None: ... - def fit( - self: BaseRandomProjection_Self, X: MatrixLike, y: Any = None - ) -> BaseRandomProjection_Self | SparseRandomProjection: ... + def fit(self, X: MatrixLike, y: Any = None) -> Self | SparseRandomProjection: ... def inverse_transform(self, X: MatrixLike) -> ndarray: ... class GaussianRandomProjection(BaseRandomProjection): diff --git a/stubs/sklearn/semi_supervised/_label_propagation.pyi b/stubs/sklearn/semi_supervised/_label_propagation.pyi index 0b591bf9..678ac1a9 100644 --- a/stubs/sklearn/semi_supervised/_label_propagation.pyi +++ b/stubs/sklearn/semi_supervised/_label_propagation.pyi @@ -1,7 +1,8 @@ import warnings from abc import ABCMeta, abstractmethod as abstractmethod from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, Literal, TypeVar +from typing import Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -18,9 +19,6 @@ from ..utils.extmath import safe_sparse_dot as safe_sparse_dot from ..utils.multiclass import check_classification_targets as check_classification_targets from ..utils.validation import check_is_fitted as check_is_fitted -BaseLabelPropagation_Self = TypeVar("BaseLabelPropagation_Self", bound=BaseLabelPropagation) -LabelPropagation_Self = TypeVar("LabelPropagation_Self", bound=LabelPropagation) - class BaseLabelPropagation(ClassifierMixin, BaseEstimator, metaclass=ABCMeta): _parameter_constraints: ClassVar[dict] = ... @@ -37,7 +35,7 @@ class BaseLabelPropagation(ClassifierMixin, BaseEstimator, metaclass=ABCMeta): ) -> None: ... def predict(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... - def fit(self: BaseLabelPropagation_Self, X: MatrixLike, y: ArrayLike) -> BaseLabelPropagation_Self | LabelSpreading: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self | LabelSpreading: ... class LabelPropagation(BaseLabelPropagation): n_iter_: int = ... @@ -62,7 +60,7 @@ class LabelPropagation(BaseLabelPropagation): tol: float = 1e-3, n_jobs: None | Int = None, ) -> None: ... - def fit(self: LabelPropagation_Self, X: MatrixLike, y: ArrayLike) -> LabelPropagation_Self: ... + def fit(self, X: MatrixLike, y: ArrayLike) -> Self: ... class LabelSpreading(BaseLabelPropagation): n_iter_: int = ... diff --git a/stubs/sklearn/semi_supervised/_self_training.pyi b/stubs/sklearn/semi_supervised/_self_training.pyi index ed6ba56e..14cc848b 100644 --- a/stubs/sklearn/semi_supervised/_self_training.pyi +++ b/stubs/sklearn/semi_supervised/_self_training.pyi @@ -1,6 +1,7 @@ import warnings from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -12,8 +13,6 @@ from ..utils._param_validation import HasMethods as HasMethods, Interval as Inte from ..utils.metaestimators import available_if as available_if from ..utils.validation import check_is_fitted as check_is_fitted -SelfTrainingClassifier_Self = TypeVar("SelfTrainingClassifier_Self", bound=SelfTrainingClassifier) - __all__ = ["SelfTrainingClassifier"] class SelfTrainingClassifier(MetaEstimatorMixin, BaseEstimator): @@ -39,7 +38,7 @@ class SelfTrainingClassifier(MetaEstimatorMixin, BaseEstimator): max_iter: None | int = 10, verbose: bool = False, ) -> None: ... - def fit(self: SelfTrainingClassifier_Self, X: MatrixLike | ArrayLike, y: ArrayLike) -> SelfTrainingClassifier_Self: ... + def fit(self, X: MatrixLike | ArrayLike, y: ArrayLike) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... def predict_proba(self, X: MatrixLike | ArrayLike) -> ndarray: ... def decision_function(self, X: MatrixLike | ArrayLike) -> ndarray: ... diff --git a/stubs/sklearn/svm/_base.pyi b/stubs/sklearn/svm/_base.pyi index 6e60841b..6f3f4333 100644 --- a/stubs/sklearn/svm/_base.pyi +++ b/stubs/sklearn/svm/_base.pyi @@ -1,7 +1,8 @@ import warnings from abc import ABCMeta, abstractmethod from numbers import Integral as Integral, Real as Real -from typing import Callable, ClassVar, TypeVar +from typing import Callable, ClassVar +from typing_extensions import Self import numpy as np import scipy.sparse as sp @@ -24,8 +25,6 @@ from ..utils.metaestimators import available_if as available_if from ..utils.multiclass import check_classification_targets as check_classification_targets from ..utils.validation import check_consistent_length as check_consistent_length, check_is_fitted as check_is_fitted -BaseLibSVM_Self = TypeVar("BaseLibSVM_Self", bound=BaseLibSVM) - LIBSVM_IMPL: list = ... class BaseLibSVM(BaseEstimator, metaclass=ABCMeta): @@ -56,11 +55,11 @@ class BaseLibSVM(BaseEstimator, metaclass=ABCMeta): random_state: None | RandomState | int, ) -> None: ... def fit( - self: BaseLibSVM_Self, + self, X: MatrixLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> BaseLibSVM_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike | ArrayLike) -> ndarray: ... @property def coef_(self) -> ndarray: ... diff --git a/stubs/sklearn/svm/_classes.pyi b/stubs/sklearn/svm/_classes.pyi index 15b1c3fe..1ccb53a1 100644 --- a/stubs/sklearn/svm/_classes.pyi +++ b/stubs/sklearn/svm/_classes.pyi @@ -1,6 +1,7 @@ from collections.abc import Mapping from numbers import Integral as Integral, Real as Real -from typing import Any, Callable, ClassVar, Literal, TypeVar +from typing import Any, Callable, ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -14,10 +15,6 @@ from ..utils._param_validation import Interval as Interval, StrOptions as StrOpt from ..utils.multiclass import check_classification_targets as check_classification_targets from ._base import BaseLibSVM, BaseSVC -OneClassSVM_Self = TypeVar("OneClassSVM_Self", bound=OneClassSVM) -LinearSVC_Self = TypeVar("LinearSVC_Self", bound=LinearSVC) -LinearSVR_Self = TypeVar("LinearSVR_Self", bound=LinearSVR) - class LinearSVC(LinearClassifierMixin, SparseCoefMixin, BaseEstimator): n_iter_: int = ... feature_names_in_: ndarray = ... @@ -45,11 +42,11 @@ class LinearSVC(LinearClassifierMixin, SparseCoefMixin, BaseEstimator): max_iter: Int = 1000, ) -> None: ... def fit( - self: LinearSVC_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> LinearSVC_Self: ... + ) -> Self: ... class LinearSVR(RegressorMixin, LinearModel): n_iter_: int = ... @@ -75,11 +72,11 @@ class LinearSVR(RegressorMixin, LinearModel): max_iter: Int = 1000, ) -> None: ... def fit( - self: LinearSVR_Self, + self, X: MatrixLike | ArrayLike, y: ArrayLike, sample_weight: None | ArrayLike = None, - ) -> LinearSVR_Self: ... + ) -> Self: ... class SVC(BaseSVC): shape_fit_: tuple = ... @@ -275,11 +272,11 @@ class OneClassSVM(OutlierMixin, BaseLibSVM): @property def class_weight_(self) -> ndarray: ... def fit( - self: OneClassSVM_Self, + self, X: MatrixLike | ArrayLike, y: Any = None, sample_weight: None | ArrayLike = None, - ) -> OneClassSVM_Self: ... + ) -> Self: ... def decision_function(self, X: MatrixLike) -> ndarray: ... def score_samples(self, X: MatrixLike) -> ndarray: ... def predict(self, X: MatrixLike) -> ndarray: ... diff --git a/stubs/sklearn/tree/_classes.pyi b/stubs/sklearn/tree/_classes.pyi index 6902644c..b1d9a041 100644 --- a/stubs/sklearn/tree/_classes.pyi +++ b/stubs/sklearn/tree/_classes.pyi @@ -5,7 +5,8 @@ from abc import ABCMeta, abstractmethod from collections.abc import Mapping, Sequence from math import ceil as ceil from numbers import Integral as Integral, Real as Real -from typing import ClassVar, Literal, TypeVar +from typing import ClassVar, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -35,8 +36,6 @@ from ._tree import ( ccp_pruning_path as ccp_pruning_path, ) -DecisionTreeRegressor_Self = TypeVar("DecisionTreeRegressor_Self", bound=DecisionTreeRegressor) - # Authors: Gilles Louppe # Peter Prettenhofer # Brian Holt @@ -182,12 +181,12 @@ class DecisionTreeRegressor(RegressorMixin, BaseDecisionTree): ccp_alpha: float = 0.0, ) -> None: ... def fit( - self: DecisionTreeRegressor_Self, + self, X: MatrixLike | ArrayLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, check_input: bool = True, - ) -> DecisionTreeRegressor_Self: ... + ) -> Self: ... class ExtraTreeClassifier(DecisionTreeClassifier): tree_: Tree = ... diff --git a/stubs/sklearn/utils/_mocking.pyi b/stubs/sklearn/utils/_mocking.pyi index 9afe1a82..de6c112d 100644 --- a/stubs/sklearn/utils/_mocking.pyi +++ b/stubs/sklearn/utils/_mocking.pyi @@ -1,5 +1,6 @@ from collections.abc import Sequence -from typing import Callable, Literal, TypeVar +from typing import Callable, Literal +from typing_extensions import Self import numpy as np from numpy import ndarray @@ -8,8 +9,6 @@ from .._typing import ArrayLike, Int, MatrixLike from ..base import BaseEstimator, ClassifierMixin from .validation import check_array as check_array, check_is_fitted as check_is_fitted -CheckingClassifier_Self = TypeVar("CheckingClassifier_Self", bound=CheckingClassifier) - class ArraySlicingWrapper: def __init__(self, array) -> None: ... def __getitem__(self, aslice): ... @@ -41,12 +40,12 @@ class CheckingClassifier(ClassifierMixin, BaseEstimator): expected_fit_params: None | Sequence[str] = None, ) -> None: ... def fit( - self: CheckingClassifier_Self, + self, X: MatrixLike, y: MatrixLike | ArrayLike, sample_weight: None | ArrayLike = None, **fit_params, - ) -> CheckingClassifier_Self: ... + ) -> Self: ... def predict(self, X: MatrixLike) -> ndarray: ... def predict_proba(self, X: MatrixLike) -> ndarray: ... def decision_function(self, X: MatrixLike) -> ndarray: ...