Skip to content

Commit

Permalink
Merge pull request #37 from jorenham/fix/scipy.stats.distributions
Browse files Browse the repository at this point in the history
fixes & improvements for `scipy.stats.distributions`
  • Loading branch information
jorenham authored Sep 7, 2024
2 parents f7d366b + 511358e commit c3ebaea
Show file tree
Hide file tree
Showing 4 changed files with 701 additions and 444 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ venv = ".venv"
venvPath = "."

deprecateTypingAliases = true
enableTypeIgnoreComments = false
reportIgnoreCommentWithoutRule = true
reportImplicitRelativeImport = true
reportInvalidCast = true
Expand Down
17 changes: 9 additions & 8 deletions scipy-stubs/_typing.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Helper types for internal use (type-check only).
from collections.abc import Callable
from typing import Literal, Protocol, TypeAlias, type_check_only
from typing import Any, Literal, Protocol, TypeAlias, type_check_only
from typing_extensions import LiteralString, TypeVar

import numpy as np
import numpy.typing as npt
import optype.numpy as onpt

__all__ = [
"RNG",
"AnyBool",
"AnyChar",
"AnyComplex",
Expand Down Expand Up @@ -40,14 +40,15 @@ Array0D: TypeAlias = np.ndarray[tuple[()], np.dtype[_SCT]]

# keep in sync with `numpy._typing._scalars`
AnyBool: TypeAlias = bool | np.bool_ | Literal[0, 1]
AnyInt: TypeAlias = int | np.integer[npt.NBitBase] | np.bool_
AnyReal: TypeAlias = int | float | np.floating[npt.NBitBase] | np.integer[npt.NBitBase] | np.bool_
AnyComplex: TypeAlias = int | float | complex | np.number[npt.NBitBase] | np.bool_
AnyInt: TypeAlias = int | np.integer[Any] | np.bool_
AnyReal: TypeAlias = int | float | np.floating[Any] | np.integer[Any] | np.bool_
AnyComplex: TypeAlias = int | float | complex | np.number[Any] | np.bool_
AnyChar: TypeAlias = str | bytes # `np.str_ <: builtins.str` and `np.bytes_ <: builtins.bytes`
AnyScalar: TypeAlias = int | float | complex | AnyChar | np.generic

# numpy literals
Seed: TypeAlias = int | np.random.Generator | np.random.RandomState
RNG: TypeAlias = np.random.Generator | np.random.RandomState
Seed: TypeAlias = int | RNG
CorrelateMode: TypeAlias = Literal["valid", "same", "full"]

# scipy literals
Expand All @@ -57,9 +58,9 @@ NanPolicy: TypeAlias = Literal["raise", "propagate", "omit"]
@type_check_only
class _FortranFunction(Protocol):
@property
def dtype(self) -> np.dtype[np.number[npt.NBitBase]]: ...
def dtype(self) -> np.dtype[np.number[Any]]: ...
@property
def int_dtype(self) -> np.dtype[np.integer[npt.NBitBase]]: ...
def int_dtype(self) -> np.dtype[np.integer[Any]]: ...
@property
def module_name(self) -> LiteralString: ...
@property
Expand Down
70 changes: 41 additions & 29 deletions scipy-stubs/stats/_continuous_distns.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
from ._distn_infrastructure import _rv_continuous_0, rv_continuous

__all__ = [
"alpha",
Expand Down Expand Up @@ -119,33 +119,60 @@ __all__ = [
"wrapcauchy",
]

class ksone_gen(rv_continuous): ...
class kstwo_gen(rv_continuous): ...
class kstwobign_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):
# without shape params
class anglit_gen(_rv_continuous_0): ...
class arcsine_gen(_rv_continuous_0): ...
class cauchy_gen(_rv_continuous_0): ...
class cosine_gen(_rv_continuous_0): ...
class expon_gen(_rv_continuous_0): ...
class gibrat_gen(_rv_continuous_0): ...
class gumbel_l_gen(_rv_continuous_0): ...
class gumbel_r_gen(_rv_continuous_0): ...
class halfcauchy_gen(_rv_continuous_0): ...
class halflogistic_gen(_rv_continuous_0): ...
class halfnorm_gen(_rv_continuous_0): ...
class hypsecant_gen(_rv_continuous_0): ...
class kstwobign_gen(_rv_continuous_0): ...
class laplace_gen(_rv_continuous_0): ...
class levy_gen(_rv_continuous_0): ...
class levy_l_gen(_rv_continuous_0): ...
class logistic_gen(_rv_continuous_0): ...
class maxwell_gen(_rv_continuous_0): ...
class moyal_gen(_rv_continuous_0): ...

class norm_gen(_rv_continuous_0):
@override
def fit(self, /, data: _AnyArray_f8_in, **kwds: _Scalar_f8_in) -> tuple[np.float64, np.float64]: ... # type: ignore[override]
def fit( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
self,
/,
data: _AnyArray_f8_in,
floc: _Scalar_f8_in | None = None,
fscale: _Scalar_f8_in | None = None,
**kwds: _Scalar_f8_in,
) -> tuple[np.float64, np.float64]: ...

class rayleigh_gen(_rv_continuous_0): ...
class semicircular_gen(_rv_continuous_0): ...
class uniform_gen(_rv_continuous_0): ...
class wald_gen(_rv_continuous_0): ...

# with shape params
class ksone_gen(rv_continuous): ...
class kstwo_gen(rv_continuous): ...
class alpha_gen(rv_continuous): ...
class anglit_gen(rv_continuous): ...
class arcsine_gen(rv_continuous): ...
class beta_gen(rv_continuous): ...
class betaprime_gen(rv_continuous): ...
class bradford_gen(rv_continuous): ...
class burr_gen(rv_continuous): ...
class burr12_gen(rv_continuous): ...
class fisk_gen(burr_gen): ...
class cauchy_gen(rv_continuous): ...
class chi_gen(rv_continuous): ...
class chi2_gen(rv_continuous): ...
class cosine_gen(rv_continuous): ...
class dgamma_gen(rv_continuous): ...
class dweibull_gen(rv_continuous): ...
class expon_gen(rv_continuous): ...
class exponnorm_gen(rv_continuous): ...
class exponweib_gen(rv_continuous): ...
class exponpow_gen(rv_continuous): ...
Expand All @@ -166,12 +193,6 @@ class gengamma_gen(rv_continuous): ...
class genhalflogistic_gen(rv_continuous): ...
class genhyperbolic_gen(rv_continuous): ...
class gompertz_gen(rv_continuous): ...
class gumbel_r_gen(rv_continuous): ...
class gumbel_l_gen(rv_continuous): ...
class halfcauchy_gen(rv_continuous): ...
class halflogistic_gen(rv_continuous): ...
class halfnorm_gen(rv_continuous): ...
class hypsecant_gen(rv_continuous): ...
class gausshyper_gen(rv_continuous): ...
class invgamma_gen(rv_continuous): ...
class invgauss_gen(rv_continuous): ...
Expand All @@ -181,20 +202,13 @@ class invweibull_gen(rv_continuous): ...
class jf_skew_t_gen(rv_continuous): ...
class johnsonsb_gen(rv_continuous): ...
class johnsonsu_gen(rv_continuous): ...
class laplace_gen(rv_continuous): ...
class laplace_asymmetric_gen(rv_continuous): ...
class levy_gen(rv_continuous): ...
class levy_l_gen(rv_continuous): ...
class logistic_gen(rv_continuous): ...
class loggamma_gen(rv_continuous): ...
class loglaplace_gen(rv_continuous): ...
class lognorm_gen(rv_continuous): ...
class gibrat_gen(rv_continuous): ...
class maxwell_gen(rv_continuous): ...
class mielke_gen(rv_continuous): ...
class kappa4_gen(rv_continuous): ...
class kappa3_gen(rv_continuous): ...
class moyal_gen(rv_continuous): ...
class nakagami_gen(rv_continuous): ...
class ncx2_gen(rv_continuous): ...
class ncf_gen(rv_continuous): ...
Expand All @@ -207,13 +221,13 @@ class powerlaw_gen(rv_continuous): ...
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):
fit_note: ClassVar[LiteralString] = ...

class rice_gen(rv_continuous): ...
class irwinhall_gen(rv_continuous): ...
class recipinvgauss_gen(rv_continuous): ...
class semicircular_gen(rv_continuous): ...
class skewcauchy_gen(rv_continuous): ...
class skewnorm_gen(rv_continuous): ...
class trapezoid_gen(rv_continuous): ...
Expand All @@ -226,9 +240,7 @@ class truncexpon_gen(rv_continuous): ...
class truncnorm_gen(rv_continuous): ...
class truncpareto_gen(rv_continuous): ...
class tukeylambda_gen(rv_continuous): ...
class uniform_gen(rv_continuous): ...
class vonmises_gen(rv_continuous): ...
class wald_gen(invgauss_gen): ...
class wrapcauchy_gen(rv_continuous): ...
class gennorm_gen(rv_continuous): ...
class halfgennorm_gen(rv_continuous): ...
Expand Down
Loading

0 comments on commit c3ebaea

Please sign in to comment.