Skip to content

Commit

Permalink
Merge pull request #17 from jorenham/fix/scipy.stats.distributions
Browse files Browse the repository at this point in the history
fix `scipy.stats.distributions` stubtests
  • Loading branch information
jorenham authored Sep 4, 2024
2 parents a4c26de + 9b0cb61 commit 5f5e44f
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 120 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
]
Expand Down
4 changes: 4 additions & 0 deletions scipy-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ __all__ = [
"AnyScalar",
"Array0D",
"CorrelateMode",
"NanPolicy",
"Seed",
"Untyped",
"UntypedArray",
Expand Down Expand Up @@ -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):
Expand Down
33 changes: 28 additions & 5 deletions scipy-stubs/stats/_continuous_distns.pyi
Original file line number Diff line number Diff line change
@@ -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__ = [
Expand Down Expand Up @@ -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): ...
Expand Down Expand Up @@ -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): ...
Expand All @@ -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): ...

Expand Down
14 changes: 10 additions & 4 deletions scipy-stubs/stats/_discrete_distns.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Final
from typing import ClassVar, Final

from ._distn_infrastructure import rv_discrete

Expand Down Expand Up @@ -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]
Expand Down
Loading

0 comments on commit 5f5e44f

Please sign in to comment.