diff --git a/README.md b/README.md index 3686543a..a0eb4b31 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ pyright), the "type completeness score" is **42.6%**. | `scipy.special.cython_special` | 2: partial | | `scipy.stats` | 2: partial | | `scipy.stats.contingency` | 1: skeleton | -| `scipy.stats.distributions` | 3: ready | +| `scipy.stats.distributions` | 4: done | | `scipy.stats.mstats` | 1: skeleton | | `scipy.stats.qmc` | 2: partial | | `scipy.stats.sampling` | 1: skeleton | diff --git a/pyproject.toml b/pyproject.toml index 8399077b..90af1aa4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,11 +48,10 @@ type = "poetry" [tool.poe.tasks] lint = "ruff check" -# stubtest = "stubtest --ignore-positional-only --mypy-config-file=pyproject.toml --allowlist=tests/stubtest/allowlist.txt scipy" verifytypes = "basedpyright --level error --verifytypes scipy-stubs" [tool.poe.tasks.stubtest] -cmd = "stubtest --ignore-positional-only --mypy-config-file=pyproject.toml --allowlist=tests/stubtest/allowlist.txt $modules" +cmd = "stubtest --mypy-config-file=pyproject.toml --allowlist=tests/stubtest/allowlist.txt $modules" args = [ {name = "modules", positional = true, multiple = true, default = "scipy"}, ] diff --git a/scipy-stubs/_typing.pyi b/scipy-stubs/_typing.pyi index 59aab861..46477dbc 100644 --- a/scipy-stubs/_typing.pyi +++ b/scipy-stubs/_typing.pyi @@ -16,6 +16,7 @@ __all__ = [ "AnyScalar", "Array0D", "CorrelateMode", + "NanPolicy", "Seed", "Untyped", "UntypedArray", @@ -49,6 +50,9 @@ AnyScalar: TypeAlias = int | float | complex | AnyChar | np.generic Seed: TypeAlias = int | np.random.Generator | np.random.RandomState CorrelateMode: TypeAlias = Literal["valid", "same", "full"] +# scipy literals +NanPolicy: TypeAlias = Literal["raise", "propagate", "omit"] + # used in `scipy.linalg.blas` and `scipy.linalg.lapack` @type_check_only class _FortranFunction(Protocol): diff --git a/scipy-stubs/stats/_continuous_distns.pyi b/scipy-stubs/stats/_continuous_distns.pyi index 8c947a30..f7948492 100644 --- a/scipy-stubs/stats/_continuous_distns.pyi +++ b/scipy-stubs/stats/_continuous_distns.pyi @@ -1,6 +1,10 @@ -from typing import Final -from typing_extensions import deprecated +from collections.abc import Sequence +from typing import Any, ClassVar, Final, TypeAlias +from typing_extensions import LiteralString, deprecated, override +import numpy as np +import numpy.typing as npt +import optype.numpy as onpt from ._distn_infrastructure import rv_continuous __all__ = [ @@ -118,7 +122,14 @@ __all__ = [ class ksone_gen(rv_continuous): ... class kstwo_gen(rv_continuous): ... class kstwobign_gen(rv_continuous): ... -class norm_gen(rv_continuous): ... + +_Scalar_f8_in: TypeAlias = np.float64 | np.float32 | np.float16 | np.integer[Any] | np.bool_ +_AnyArray_f8_in: TypeAlias = float | onpt.CanArray[tuple[int, ...], np.dtype[_Scalar_f8_in]] | Sequence[_AnyArray_f8_in] + +class norm_gen(rv_continuous): + @override + def fit(self, /, data: _AnyArray_f8_in, **kwds: _Scalar_f8_in) -> tuple[np.float64, np.float64]: ... # type: ignore[override] + class alpha_gen(rv_continuous): ... class anglit_gen(rv_continuous): ... class arcsine_gen(rv_continuous): ... @@ -197,7 +208,8 @@ class powerlognorm_gen(rv_continuous): ... class powernorm_gen(rv_continuous): ... class rdist_gen(rv_continuous): ... class rayleigh_gen(rv_continuous): ... -class reciprocal_gen(rv_continuous): ... +class reciprocal_gen(rv_continuous): + fit_note: ClassVar[LiteralString] = ... class rice_gen(rv_continuous): ... class irwinhall_gen(rv_continuous): ... class recipinvgauss_gen(rv_continuous): ... @@ -222,7 +234,18 @@ class gennorm_gen(rv_continuous): ... class halfgennorm_gen(rv_continuous): ... class crystalball_gen(rv_continuous): ... class argus_gen(rv_continuous): ... -class rv_histogram(rv_continuous): ... + +_Seed: TypeAlias = np.random.Generator | np.random.RandomState | int + +class rv_histogram(rv_continuous): + def __init__( + self, + histogram: tuple[npt.NDArray[np.floating[Any]], npt.NDArray[np.inexact[Any]]], + *args: float | LiteralString | _Seed, + density: bool | None = None, + **kwargs: float | LiteralString | _Seed, + ) -> None: ... + class studentized_range_gen(rv_continuous): ... class rel_breitwigner_gen(rv_continuous): ... diff --git a/scipy-stubs/stats/_discrete_distns.pyi b/scipy-stubs/stats/_discrete_distns.pyi index 0182e172..20faa8cd 100644 --- a/scipy-stubs/stats/_discrete_distns.pyi +++ b/scipy-stubs/stats/_discrete_distns.pyi @@ -1,4 +1,4 @@ -from typing import Final +from typing import ClassVar, Final from ._distn_infrastructure import rv_discrete @@ -43,9 +43,15 @@ class zipfian_gen(rv_discrete): ... class dlaplace_gen(rv_discrete): ... class skellam_gen(rv_discrete): ... class yulesimon_gen(rv_discrete): ... -class _nchypergeom_gen(rv_discrete): ... -class nchypergeom_fisher_gen(_nchypergeom_gen): ... -class nchypergeom_wallenius_gen(_nchypergeom_gen): ... +class _nchypergeom_gen(rv_discrete): + rvs_name: ClassVar = None + dist: ClassVar = None +class nchypergeom_fisher_gen(_nchypergeom_gen): + rvs_name: ClassVar = "rvs_fisher" + dist: ClassVar[type] = ... # scipy.stats._biasedurn._PyFishersNCHypergeometric +class nchypergeom_wallenius_gen(_nchypergeom_gen): + rvs_name: ClassVar = "rvs_wallenius" + dist: ClassVar[type] = ... # scipy.stats._biasedurn._PyWalleniusNCHypergeometric binom: Final[binom_gen] bernoulli: Final[bernoulli_gen] diff --git a/scipy-stubs/stats/_distn_infrastructure.pyi b/scipy-stubs/stats/_distn_infrastructure.pyi index 94d63c26..41b46ed8 100644 --- a/scipy-stubs/stats/_distn_infrastructure.pyi +++ b/scipy-stubs/stats/_distn_infrastructure.pyi @@ -59,20 +59,22 @@ _FitMethod: TypeAlias = Literal["MLE", "MM"] ### -parse_arg_template: Final[str] +docheaders: Final[dict[str, str]] = ... +docdict: Final[dict[str, str]] = ... +docdict_discrete: Final[dict[str, str]] = ... +parse_arg_template: Final[str] = ... def argsreduce(cond: npt.NDArray[np.bool_], *args: npt.ArrayLike) -> list[npt.NDArray[np.floating[Any] | np.integer[Any]]]: ... class rv_frozen(Generic[_RVG_co]): args: Final[_RVArgs] kwds: Final[_RVKwds] - @property - def dist(self, /) -> _RVG_co: ... + dist: _RVG_co @property def random_state(self, /) -> _RNG: ... @random_state.setter def random_state(self, seed: _Seed, /) -> None: ... - def __init__(self, dist: _RVG_co, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> None: ... + def __init__(self, /, dist: _RVG_co, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> None: ... def cdf(self, /, x: _AnyArray_f8_in) -> _AnyArray_f8_out: ... def logcdf(self, /, x: _AnyArray_f8_in) -> _AnyArray_f8_out: ... def ppf(self, /, q: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @@ -120,7 +122,7 @@ class rv_frozen(Generic[_RVG_co]): def var(self, /) -> _AnyArray_f8_out: ... def std(self, /) -> _AnyArray_f8_out: ... # order defaults to `None`, but that will `raise TypeError` - def moment(self, /, order: int) -> np.float64: ... + def moment(self, /, order: int | None = None) -> np.float64: ... def entropy(self, /) -> _AnyArray_f8_out: ... def interval( self, @@ -160,12 +162,6 @@ class rv_generic: @random_state.setter def random_state(self, seed: _Seed, /) -> None: ... @abc.abstractmethod - def _unpack_loc_scale( - self, - /, - theta: Sequence[_AnyArray_f8_in], - ) -> tuple[_AnyArray_f8_in, _AnyArray_f8_in, tuple[_AnyArray_f8_in]]: ... - @abc.abstractmethod def _attach_methods(self, /) -> None: ... def _attach_argparser_methods(self, /) -> None: ... def _construct_argparser( @@ -273,14 +269,14 @@ class rv_generic: def _get_support(self, /, *args: _AnyArray_f8_in, **kwargs: _AnyArray_f8_in) -> tuple[_AnyArray_f8_in, _AnyArray_f8_in]: ... def _support_mask( self, - x: npt.NDArray[_Scalar_uif], /, + x: npt.NDArray[_Scalar_uif], *args: float | _Scalar_uif | npt.NDArray[_Scalar_uif], ) -> npt.NDArray[np.bool_]: ... def _open_support_mask( self, - x: npt.NDArray[_Scalar_uif], /, + x: npt.NDArray[_Scalar_uif], *args: float | _Scalar_uif | npt.NDArray[_Scalar_uif], ) -> npt.NDArray[np.bool_]: ... def _rvs( @@ -290,11 +286,11 @@ class rv_generic: size: int | tuple[int, ...] | None = None, random_state: _Seed | None = None, ) -> _AnyArray_f8_out: ... - def _logcdf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _sf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _logsf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _ppf(self, q: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _isf(self, q: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _logcdf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _sf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _logsf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _ppf(self, /, q: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _isf(self, /, q: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... @overload def rvs( self, @@ -336,9 +332,9 @@ class rv_generic: @overload def entropy(self, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @overload - def moment(self, order: int, /, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... + def moment(self, /, order: int, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... @overload - def moment(self, order: int, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def moment(self, /, order: int, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @overload def median(self, /, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... @overload @@ -358,16 +354,16 @@ class rv_generic: @overload def interval( self, - confidence: _AnyScalar_f8_in, /, + confidence: _AnyScalar_f8_in, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in, ) -> tuple[np.float64, np.float64]: ... @overload def interval( self, - confidence: _AnyArray_f8_out, /, + confidence: _AnyArray_f8_out, *args: _AnyArray_f8_out, **kwds: _AnyArray_f8_out, ) -> tuple[np.float64, np.float64] | tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]: ... @@ -381,14 +377,7 @@ class rv_generic: **kwds: _AnyArray_f8_in, ) -> tuple[np.float64, np.float64] | tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]: ... def nnlf(self, /, theta: Sequence[_Scalar_f8_in], x: onpt.AnyIntegerArray | onpt.AnyFloatingArray) -> _AnyArray_f8_out: ... - def _nnlf(self, x: npt.NDArray[np.floating[Any]], /, *args: _Scalar_f8_in) -> _AnyArray_f8_out: ... - def _nnlf_and_penalty( - self, - /, - x: npt.NDArray[_Scalar_uif], - args: Sequence[_Scalar_f8_in], - log_fitfun: Callable[..., npt.NDArray[np.float64]], - ) -> np.float64: ... + def _nnlf(self, /, x: npt.NDArray[np.floating[Any]], *args: _Scalar_f8_in) -> _AnyArray_f8_out: ... def _penalized_nnlf( self, /, @@ -419,35 +408,19 @@ class _ShapeInfo: class _rv_mixin: def _attach_methods(self, /) -> None: ... def generic_moment(self, /, n: onpt.AnyIntegerArray, *args: _Scalar_f8_in) -> npt.NDArray[np.float64]: ... - def _logpxf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _cdf_single(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in) -> np.float64: ... - def _cdfvec(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _cdf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _ppfvec(self, q: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - @overload - def ppf(self, q: _Scalar_f8_in, /, *args: _Scalar_f8_in) -> np.float64: ... - @overload - def ppf(self, q: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... - @overload - def isf(self, q: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + def _logpxf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _cdf_single(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in) -> np.float64: ... + def _cdfvec(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _cdf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _ppfvec(self, /, q: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... @overload - def isf(self, q: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def ppf(self, /, q: _Scalar_f8_in, *args: _Scalar_f8_in) -> np.float64: ... @overload - def cdf(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + def ppf(self, /, q: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @overload - def cdf(self, x: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def isf(self, /, q: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... @overload - def logcdf(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... - @overload - def logcdf(self, x: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... - @overload - def sf(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... - @overload - def sf(self, x: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... - @overload - def logsf(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... - @overload - def logsf(self, x: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def isf(self, /, q: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... def _unpack_loc_scale( self, /, @@ -466,13 +439,12 @@ class rv_continuous(_rv_mixin, rv_generic): def __init__( self, /, - *, - name: LiteralString, momtype: Literal[0, 1] = 1, a: float | None = None, b: float | None = None, xtol: float = 1e-14, badvalue: float | None = None, + name: LiteralString | None = None, longname: LiteralString | None = None, shapes: LiteralString | None = None, seed: _Seed | None = None, @@ -481,16 +453,33 @@ class rv_continuous(_rv_mixin, rv_generic): def __call__(self, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> rv_continuous_frozen[Self]: ... @override def freeze(self, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> rv_continuous_frozen[Self]: ... - def _pdf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... - def _logpdf(self, x: npt.NDArray[_Scalar_uif], /, *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _pdf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + def _logpdf(self, /, x: npt.NDArray[_Scalar_uif], *args: npt.NDArray[_Scalar_uif]) -> npt.NDArray[np.float64]: ... + @overload + def pdf(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + @overload + def pdf(self, /, x: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def logpdf(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + @overload + def logpdf(self, /, x: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @overload - def pdf(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + def cdf(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... @overload - def pdf(self, x: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def cdf(self, /, x: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @overload - def logpdf(self, x: _Scalar_f8_in, /, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + def logcdf(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... @overload - def logpdf(self, x: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def logcdf(self, /, x: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def sf(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + @overload + def sf(self, /, x: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def logsf(self, /, x: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + @overload + def logsf(self, /, x: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def _nnlf_and_penalty(self, /, x: npt.NDArray[_Scalar_uif], args: Sequence[_Scalar_f8_in]) -> np.float64: ... def _fitstart( self, /, @@ -518,8 +507,8 @@ class rv_continuous(_rv_mixin, rv_generic): ) -> np.float64: ... def fit( self, - data: _AnyArray_f8_in, /, + data: _AnyArray_f8_in, *args: _Scalar_f8_in, optimizer: Callable[ [npt.NDArray[np.float64], tuple[np.float64, ...], tuple[np.float64, ...], bool], @@ -530,11 +519,11 @@ class rv_continuous(_rv_mixin, rv_generic): ) -> tuple[np.float64, ...]: ... def _fit_loc_scale_support( self, - data: _AnyArray_f8_in, /, + data: _AnyArray_f8_in, *args: _Scalar_f8_in, ) -> tuple[np.intp | np.float64, np.intp | np.float64 | float]: ... - def fit_loc_scale(self, data: _AnyArray_f8_in, /, *args: _Scalar_f8_in) -> tuple[np.float64, np.float64]: ... + def fit_loc_scale(self, /, data: _AnyArray_f8_in, *args: _Scalar_f8_in) -> tuple[np.float64, np.float64]: ... def expect( self, /, @@ -549,51 +538,81 @@ class rv_continuous(_rv_mixin, rv_generic): **kwds: Any, ) -> np.float64: ... + # NOTE: + class rv_discrete(_rv_mixin, rv_generic): inc: int moment_tol: float - @overload def __new__( cls, - /, - *, - name: LiteralString, a: float = 0, b: float = ..., + name: LiteralString | None = None, badvalue: float | None = None, moment_tol: float = 1e-08, + values: tuple[_AnyArray_f8_in, _AnyArray_f8_in] | None = None, inc: int = 1, longname: LiteralString | None = None, shapes: LiteralString | None = None, seed: _Seed | None = None, - values: None = None, ) -> Self: ... - @overload - def __new__( - cls, - /, - *, - name: LiteralString, - values: tuple[_AnyArray_f8_in, _AnyArray_f8_in], - a: float = 0, - b: float = ..., - badvalue: float | None = None, - moment_tol: float = 1e-08, - inc: int = 1, - longname: LiteralString | None = None, - shapes: LiteralString | None = None, - seed: _Seed | None = None, - ) -> rv_sample: ... - def __init__( + # NOTE: Mypy (still) doesn't conform to the typing spec for `__new__` (mypy==1.11.2). + # @overload + # def __new__( + # cls, + # /, + # a: float = 0, + # b: float = ..., + # name: LiteralString | None = None, + # badvalue: float | None = None, + # moment_tol: float = 1e-08, + # values: None = None, + # inc: int = 1, + # longname: LiteralString | None = None, + # shapes: LiteralString | None = None, + # seed: _Seed | None = None, + # ) -> Self: ... + # @overload + # def __new__( + # cls, + # a: float, + # b: float, + # name: LiteralString | None, + # badvalue: float | None, + # moment_tol: float, + # values: tuple[_AnyArray_f8_in, _AnyArray_f8_in], + # /, + # inc: int = 1, + # longname: LiteralString | None = None, + # shapes: LiteralString | None = None, + # seed: _Seed | None = None, + # ) -> rv_sample: ... + # @overload + # def __new__( + # cls, + # /, + # a: float = 0, + # b: float = ..., + # name: LiteralString | None = None, + # badvalue: float | None = None, + # moment_tol: float = 1e-08, + # *, + # values: tuple[_AnyArray_f8_in, _AnyArray_f8_in], + # inc: int = 1, + # longname: LiteralString | None = None, + # shapes: LiteralString | None = None, + # seed: _Seed | None = None, + # ) -> rv_sample: ... + def __init__( # pyright: ignore[reportInconsistentConstructor] self, /, - *, a: float = 0, b: float = ..., name: LiteralString | None = None, badvalue: float | None = None, moment_tol: float = 1e-08, + values: None = None, inc: int = 1, longname: LiteralString | None = None, shapes: LiteralString | None = None, @@ -612,13 +631,29 @@ class rv_discrete(_rv_mixin, rv_generic): **kwds: _AnyArray_f8_in, ) -> int | npt.NDArray[np.int64]: ... @overload - def pmf(self, k: _AnyScalar_f8_in, /, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... + def pmf(self, /, k: _AnyScalar_f8_in, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... + @overload + def pmf(self, /, k: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def logpmf(self, /, k: _AnyScalar_f8_in, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... + @overload + def logpmf(self, /, k: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def cdf(self, /, k: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + @overload + def cdf(self, /, k: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def logcdf(self, /, k: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... + @overload + def logcdf(self, /, k: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + @overload + def sf(self, /, k: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... @overload - def pmf(self, k: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def sf(self, /, k: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... @overload - def logpmf(self, k: _AnyScalar_f8_in, /, *args: _AnyScalar_f8_in, **kwds: _AnyScalar_f8_in) -> np.float64: ... + def logsf(self, /, k: _Scalar_f8_in, *args: _Scalar_f8_in, **kwds: _Scalar_f8_in) -> np.float64: ... @overload - def logpmf(self, k: _AnyArray_f8_in, /, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... + def logsf(self, /, k: _AnyArray_f8_in, *args: _AnyArray_f8_in, **kwds: _AnyArray_f8_in) -> _AnyArray_f8_out: ... def expect( self, /, @@ -635,30 +670,30 @@ class rv_discrete(_rv_mixin, rv_generic): class rv_sample(rv_discrete, Generic[_XT_co, _PT_co]): badvalue: Final[float] + a: _XT_co + b: _XT_co + xk: np.ndarray[tuple[int], np.dtype[_XT_co]] + pk: np.ndarray[tuple[int], np.dtype[_PT_co]] + qvals: np.ndarray[tuple[int], np.dtype[_PT_co]] shapes: Final = " " - @property - def xk(self, /) -> np.ndarray[tuple[int], np.dtype[_XT_co]]: ... - @property - def pk(self, /) -> np.ndarray[tuple[int], np.dtype[_PT_co]]: ... - @property - def qvals(self, /) -> np.ndarray[tuple[int], np.dtype[_PT_co]]: ... - @property - def a(self, /) -> _XT_co: ... - @property - def b(self, /) -> _XT_co: ... - def __init__( + def __init__( # pyright: ignore[reportInconsistentConstructor] self, /, - *, - values: tuple[_AnyArray_f8_in, _AnyArray_f8_in], + a: spt.AnyReal = 0, + b: spt.AnyReal = ..., + name: LiteralString | None = None, badvalue: float | None = None, moment_tol: float = 1e-08, + values: tuple[_AnyArray_f8_in, _AnyArray_f8_in] | None = None, inc: int = 1, - name: LiteralString | None = None, longname: LiteralString | None = None, + shapes: LiteralString | None = None, seed: _Seed | None = None, ) -> None: ... - def vecentropy(self, /) -> np.float64: ... + def _entropy(self, /) -> np.float64: ... + vecentropy: Final = _entropy + @override + def generic_moment(self, /, n: onpt.AnyIntegerArray | int | Sequence[int]) -> npt.NDArray[np.float64]: ... # type: ignore[override] def get_distribution_names( namespace_pairs: Iterable[tuple[str, type]], diff --git a/scipy-stubs/stats/_entropy.pyi b/scipy-stubs/stats/_entropy.pyi index cbca04d4..dd224286 100644 --- a/scipy-stubs/stats/_entropy.pyi +++ b/scipy-stubs/stats/_entropy.pyi @@ -5,6 +5,7 @@ from typing import Any, Literal import numpy as np import numpy.typing as npt +import scipy._typing as spt __all__ = ["differential_entropy", "entropy"] @@ -13,6 +14,9 @@ def entropy( qk: npt.ArrayLike | None = None, base: float | None = None, axis: int = 0, + *, + nan_policy: spt.NanPolicy = "propagate", + keepdims: bool = False, ) -> np.floating[Any] | npt.NDArray[np.floating[Any]]: ... def differential_entropy( values: npt.ArrayLike, @@ -21,4 +25,6 @@ def differential_entropy( base: float | None = None, axis: int = 0, method: Literal["vasicek", "van es", "ebrahimi", "correa", "auto"] = "auto", + nan_policy: spt.NanPolicy = "propagate", + keepdims: bool = False, ) -> np.floating[Any] | npt.NDArray[np.floating[Any]]: ...