Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix stubtest build errors in scipy.stats #77

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions scipy-stubs/stats/_multicomp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ from typing import Literal

import numpy as np
import numpy.typing as npt
from scipy import stats as stats
from scipy._lib._util import DecimalNumber as DecimalNumber, SeedType as SeedType
from scipy.stats._common import ConfidenceInterval as ConfidenceInterval
from scipy._typing import AnyReal, Seed
from ._common import ConfidenceInterval

__all__ = ["dunnett"]

@dataclass
class DunnettResult:
statistic: npt.NDArray[np.float64]
pvalue: npt.NDArray[np.float64]
def confidence_interval(self, confidence_level: DecimalNumber = 0.95) -> ConfidenceInterval: ...
def confidence_interval(self, confidence_level: AnyReal = 0.95) -> ConfidenceInterval: ...

def dunnett(
*samples: npt.ArrayLike,
control: npt.ArrayLike,
alternative: Literal["two-sided", "less", "greater"] = "two-sided",
random_state: SeedType = None,
random_state: Seed | None = None,
) -> DunnettResult: ...
88 changes: 49 additions & 39 deletions scipy-stubs/stats/_qmc.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABC, abstractmethod
from typing import ClassVar, Literal, TypeVar, overload
from typing_extensions import override

import numpy as np
import numpy.typing as npt
from scipy._lib._util import DecimalNumber, IntNumber, SeedType
from scipy._typing import Untyped, UntypedArray
from scipy._typing import AnyInt, AnyReal, Seed, Untyped, UntypedArray

__all__ = [
"Halton",
Expand All @@ -23,7 +23,7 @@ __all__ = [
_RNGT = TypeVar("_RNGT", bound=np.random.Generator | np.random.RandomState)

@overload
def check_random_state(seed: IntNumber | None = ...) -> np.random.Generator: ...
def check_random_state(seed: AnyInt | None = ...) -> np.random.Generator: ...
@overload
def check_random_state(seed: _RNGT) -> _RNGT: ...
def scale(sample: npt.ArrayLike, l_bounds: npt.ArrayLike, u_bounds: npt.ArrayLike, *, reverse: bool = False) -> UntypedArray: ...
Expand All @@ -32,25 +32,25 @@ def discrepancy(
*,
iterative: bool = False,
method: Literal["CD", "WD", "MD", "L2-star"] = "CD",
workers: IntNumber = 1,
workers: AnyInt = 1,
) -> float: ...
def geometric_discrepancy(
sample: npt.ArrayLike,
method: Literal["mindist", "mst"] = "mindist",
metric: str = "euclidean",
) -> float: ...
def update_discrepancy(x_new: npt.ArrayLike, sample: npt.ArrayLike, initial_disc: DecimalNumber) -> float: ...
def update_discrepancy(x_new: npt.ArrayLike, sample: npt.ArrayLike, initial_disc: AnyReal) -> float: ...
def primes_from_2_to(n: int) -> UntypedArray: ...
def n_primes(n: IntNumber) -> list[int]: ...
def n_primes(n: AnyInt) -> list[int]: ...
def van_der_corput(
n: IntNumber,
base: IntNumber = 2,
n: AnyInt,
base: AnyInt = 2,
*,
start_index: IntNumber = 0,
start_index: AnyInt = 0,
scramble: bool = False,
permutations: npt.ArrayLike | None = None,
seed: SeedType = None,
workers: IntNumber = 1,
seed: Seed | None = None,
workers: AnyInt = 1,
) -> UntypedArray: ...

class QMCEngine(ABC):
Expand All @@ -62,49 +62,49 @@ class QMCEngine(ABC):
@abstractmethod
def __init__(
self,
d: IntNumber,
d: AnyInt,
*,
optimization: Literal["random-cd", "lloyd"] | None = None,
seed: SeedType = None,
seed: Seed | None = None,
) -> None: ...
def random(self, n: IntNumber = 1, *, workers: IntNumber = 1) -> UntypedArray: ...
def random(self, n: AnyInt = 1, *, workers: AnyInt = 1) -> UntypedArray: ...
def integers(
self,
l_bounds: npt.ArrayLike,
*,
u_bounds: npt.ArrayLike | None = None,
n: IntNumber = 1,
n: AnyInt = 1,
endpoint: bool = False,
workers: IntNumber = 1,
workers: AnyInt = 1,
) -> UntypedArray: ...
def reset(self) -> QMCEngine: ...
def fast_forward(self, n: IntNumber) -> QMCEngine: ...
def fast_forward(self, n: AnyInt) -> QMCEngine: ...

class Halton(QMCEngine):
seed: Untyped
base: Untyped
scramble: Untyped
def __init__(
self,
d: IntNumber,
d: AnyInt,
*,
scramble: bool = True,
optimization: Literal["random-cd", "lloyd"] | None = None,
seed: SeedType = None,
): ...
seed: Seed | None = None,
) -> None: ...

class LatinHypercube(QMCEngine):
scramble: Untyped
lhs_method: Untyped
def __init__(
self,
d: IntNumber,
d: AnyInt,
*,
scramble: bool = True,
strength: int = 1,
optimization: Literal["random-cd", "lloyd"] | None = None,
seed: SeedType = None,
): ...
seed: Seed | None = None,
) -> None: ...

class Sobol(QMCEngine):
MAXDIM: ClassVar[int]
Expand All @@ -113,16 +113,18 @@ class Sobol(QMCEngine):
maxn: Untyped
def __init__(
self,
d: IntNumber,
d: AnyInt,
*,
scramble: bool = True,
bits: IntNumber | None = None,
seed: SeedType = None,
bits: AnyInt | None = None,
seed: Seed | None = None,
optimization: Literal["random-cd", "lloyd"] | None = None,
): ...
def random_base2(self, m: IntNumber) -> UntypedArray: ...
) -> None: ...
def random_base2(self, m: AnyInt) -> UntypedArray: ...
@override
def reset(self) -> Sobol: ...
def fast_forward(self, n: IntNumber) -> Sobol: ...
@override
def fast_forward(self, n: AnyInt) -> Sobol: ...

class PoissonDisk(QMCEngine):
hypersphere_method: Untyped
Expand All @@ -134,17 +136,18 @@ class PoissonDisk(QMCEngine):
grid_size: Untyped
def __init__(
self,
d: IntNumber,
d: AnyInt,
*,
radius: DecimalNumber = 0.05,
radius: AnyReal = 0.05,
hypersphere: Literal["volume", "surface"] = "volume",
ncandidates: IntNumber = 30,
ncandidates: AnyInt = 30,
optimization: Literal["random-cd", "lloyd"] | None = None,
seed: SeedType = None,
seed: Seed | None = None,
l_bounds: npt.ArrayLike | None = None,
u_bounds: npt.ArrayLike | None = None,
): ...
) -> None: ...
def fill_space(self) -> UntypedArray: ...
@override
def reset(self) -> PoissonDisk: ...

class MultivariateNormalQMC:
Expand All @@ -157,13 +160,20 @@ class MultivariateNormalQMC:
cov_root: npt.ArrayLike | None = None,
inv_transform: bool = True,
engine: QMCEngine | None = None,
seed: SeedType = None,
): ...
def random(self, n: IntNumber = 1) -> UntypedArray: ...
seed: Seed | None = None,
) -> None: ...
def random(self, n: AnyInt = 1) -> UntypedArray: ...

class MultinomialQMC:
pvals: Untyped
n_trials: Untyped
engine: Untyped
def __init__(self, pvals: npt.ArrayLike, n_trials: IntNumber, *, engine: QMCEngine | None = None, seed: SeedType = None): ...
def random(self, n: IntNumber = 1) -> UntypedArray: ...
def __init__(
self,
pvals: npt.ArrayLike,
n_trials: AnyInt,
*,
engine: QMCEngine | None = None,
seed: Seed | None = None,
) -> None: ...
def random(self, n: AnyInt = 1) -> UntypedArray: ...
43 changes: 0 additions & 43 deletions tests/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ scipy.optimize._typing

# submodules
scipy._lib.array_api_compat.*
scipy._lib.boost_math.*
scipy._lib.cobyqa.*
scipy._lib.highs.*
scipy._lib.pocketfft.*
scipy._lib.unuran.*

# internal testing
scipy._lib.messagestream.__test__
Expand Down Expand Up @@ -62,7 +58,6 @@ scipy.sparse.linalg.eigen.test
scipy.sparse.linalg.isolve.test
scipy.sparse.linalg.tests.*
scipy.sparse.tests.*
scipy.spatial.PytestTester
scipy.spatial.tests.*
scipy.spatial.transform.tests.*
scipy.spatial.transform._rotation.__test__
Expand All @@ -72,13 +67,6 @@ scipy.stats._qmc_cy.__test__
scipy.stats._sobol.__test__

# undocumented & irrelevant internal scipy machinery
scipy._lib._uarray._backend.get_defaults
scipy._lib._uarray._backend.pickle_function
scipy._lib._uarray._backend.pickle_function
scipy._lib._uarray._backend.pickle_set_backend_context
scipy._lib._uarray._backend.pickle_skip_backend_context
scipy._lib._uarray._backend.pickle_state
scipy._lib._uarray._backend.unpickle_function
scipy._lib.decorator.DEF
scipy._lib.decorator.ArgSpec
scipy._lib.decorator.FunctionMaker
Expand All @@ -102,35 +90,4 @@ scipy._lib._ccallback.PyCFuncPtr # `final(T)` is impossible
scipy._lib._docscrape.Parameter.__replace__ # py313
scipy._lib._pep440._Version.__replace__ # py313
scipy._lib._util.FullArgSpec.__replace__ # py313
scipy._lib.decorator.ArgSpec.__replace__ # py313
scipy.integrate._quadrature.QMCQuadResult.__replace__ # py313

# TODO:
scipy.sparse._matrix.__all__
scipy.sparse.csgraph.__all__
scipy.sparse.csgraph._flow.__all__
scipy.sparse.csgraph._laplacian.__all__
scipy.sparse.csgraph._matching.__all__
scipy.sparse.csgraph._min_spanning_tree.__all__
scipy.sparse.csgraph._reordering.__all__
scipy.sparse.csgraph._shortest_path.__all__
scipy.sparse.csgraph._tools.__all__
scipy.sparse.csgraph._traversal.__all__
scipy.sparse.linalg._dsolve.__all__
scipy.sparse.linalg._dsolve._superlu.__all__
scipy.stats.__all__
scipy.stats._binomtest.__all__
scipy.stats._bws_test.__all__
scipy.stats._censored_data.__all__
scipy.stats._common.__all__
scipy.stats._continuous_distns.__all__
scipy.stats._discrete_distns.__all__
scipy.stats._distn_infrastructure.__all__
scipy.stats._distr_params.__all__
scipy.stats.distributions.__all__
scipy.stats.sampling.__all__
scipy.stats.kde.*
scipy.stats.morestats.*
scipy.stats.mstats_basic.*
scipy.stats.mstats_extras.*
scipy.stats.stats.*
Loading