Skip to content

Commit

Permalink
Merge pull request #366 from jorenham/scipy-stubs-1.14.1.5
Browse files Browse the repository at this point in the history
bump `scipy-stubs` to `1.14.1.5`
  • Loading branch information
jorenham authored Dec 4, 2024
2 parents a858169 + 0ff7dc3 commit e2f0143
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 333 deletions.
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ ci:
autoupdate_branch: "master"
autoupdate_commit_msg: "update pre-commit hooks"
skip:
- markdownlint
- codespell
- ruff
- ruff-format
- basedpyright
- basedpyright-verifytypes

Expand Down Expand Up @@ -82,7 +78,7 @@ repos:
hooks:
- id: basedpyright
name: basedpyright
entry: uv run basedpyright
entry: uv run basedpyright --threads=3
language: system
types_or: [python, pyi]

Expand Down
18 changes: 11 additions & 7 deletions lmo/_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar, cast, overload
from typing import TYPE_CHECKING, TypeAlias, TypeVar, cast, overload

import numpy as np
import numpy.polynomial as npp
Expand Down Expand Up @@ -49,27 +49,31 @@ def __dir__() -> tuple[str, ...]:
_T_shape = TypeVar("_T_shape", bound=onp.AtLeast1D)
_T_poly = TypeVar("_T_poly", bound=PolySeries)

_Float = np.float32 | np.float64

###


@overload
def eval_sh_jacobi(
n: int | lmt.Integer,
a: float,
b: float,
x: float | np.floating[Any],
) -> float: ...
x: float | _Float,
) -> float | _Float: ...
@overload
def eval_sh_jacobi(
n: int | lmt.Integer,
a: float,
b: float,
x: onp.Array[_T_shape, lmt.Floating],
) -> onp.Array[_T_shape, np.float64]: ...
x: onp.Array[_T_shape, _Float],
) -> onp.Array[_T_shape, _Float]: ...
def eval_sh_jacobi( # noqa: C901
n: int | lmt.Integer,
a: float,
b: float,
x: float | np.floating[Any] | onp.Array[_T_shape, lmt.Floating],
) -> float | onp.Array[_T_shape, np.float64]:
x: float | _Float | onp.Array[_T_shape, _Float],
) -> float | _Float | onp.Array[_T_shape, _Float]:
"""
Fast evaluation of the n-th shifted Jacobi polynomial.
Faster than pre-computing using np.Polynomial, and than
Expand Down
4 changes: 1 addition & 3 deletions lmo/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ def clean_order(
msg = f"expected {name} >= {rmin}, got {r}"
raise TypeError(msg)

# Pyright doesn't seem to realize that its internal `Unknown` "type" is literally
# defined as `Any` within gradual type-systems like Python typing...
return int(r) # pyright: ignore[reportUnknownArgumentType]
return int(r)


@overload
Expand Down
38 changes: 21 additions & 17 deletions lmo/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def __call__(self, x: _T_x, /) -> _T_x: ...


_Tuple2: TypeAlias = tuple[_T, _T]
_FloatND: TypeAlias = onp.ArrayND[np.float64]

_Float: TypeAlias = float | np.float32 | np.float64
_FloatND: TypeAlias = onp.ArrayND[np.float32 | np.float64]


_MIN_RHO: Final[float] = 1e-5
Expand All @@ -78,8 +80,8 @@ class HypothesisTestResult(NamedTuple):
hypothesis, $H_0$.
"""

statistic: float | _FloatND
pvalue: float | _FloatND
statistic: _Float | _FloatND
pvalue: _Float | _FloatND

@property
def is_valid(self) -> np.bool_ | onp.ArrayND[np.bool_]:
Expand All @@ -88,7 +90,7 @@ def is_valid(self) -> np.bool_ | onp.ArrayND[np.bool_]:

def is_significant(
self,
level: float | np.floating[Any] = 0.05,
level: _Float | np.floating[Any] = 0.05,
/,
) -> np.bool_ | onp.ArrayND[np.bool_]:
"""
Expand Down Expand Up @@ -211,7 +213,7 @@ def l_moment_gof(
trim: lmt.ToTrim = 0,
**kwargs: Any,
) -> HypothesisTestResult:
r"""
"""
Goodness-of-fit (GOF) hypothesis test for the null hypothesis that the
observed L-moments come from a distribution with the given
[`scipy.stats`][scipy.stats] distribution or cumulative distribution
Expand All @@ -224,14 +226,14 @@ def l_moment_gof(
The test statistic is the squared Mahalanobis distance between the $n$
observed L-moments, and the theoretical L-moments. It asymptically (in
sample size) follows the
[$\chi^2$](https://wikipedia.org/wiki/Chi-squared_distribution)
[`Chi-squared`](https://wikipedia.org/wiki/Chi-squared_distribution)
distribution, with $n$ degrees of freedom.
The sample L-moments are expected to be of consecutive orders
$r = 1, 2, \dots, n$.
`r = 1, 2, ..., n`.
Generally, the amount of L-moments $n$ should not be less than the amount
of parameters of the distribution, including the location and scale
parameters. Therefore, it is required to have $n \ge 2$.
parameters. Therefore, it is required to have `n <= 2`.
Notes:
The theoretical L-moments and their covariance matrix are calculated
Expand Down Expand Up @@ -273,7 +275,7 @@ def l_moment_gof(
See Also:
- [`l_moment_from_cdf`][lmo.theoretical.l_moment_from_cdf]
- ['l_moment_cov_from_cdf'][lmo.theoretical.l_moment_cov_from_cdf]
- [`l_moment_cov_from_cdf`][lmo.theoretical.l_moment_cov_from_cdf]
"""
l_r = np.asarray_chkfinite(l_moments)
Expand All @@ -297,7 +299,7 @@ def l_moment_gof(

from scipy.special import chdtrc

stat = n_obs * _gof_stat(l_r.T, lambda_r, lambda_rr).T[()]
stat: _Float | _FloatND = n_obs * _gof_stat(l_r.T, lambda_r, lambda_rr).T[()]
pval = chdtrc(n, stat)
return HypothesisTestResult(stat, pval)

Expand Down Expand Up @@ -333,7 +335,7 @@ def l_stats_gof(

from scipy.special import chdtrc

stat = n_obs * _gof_stat(t_r.T, tau_r, tau_rr).T[()]
stat: _Float | _FloatND = n_obs * _gof_stat(t_r.T, tau_r, tau_rr).T[()]
pval = chdtrc(n, stat)
return HypothesisTestResult(stat, pval)

Expand Down Expand Up @@ -366,9 +368,11 @@ def _lm2_bounds_single(r: int, trim: _Tuple2[float]) -> float:
) / (np.pi * 2 * r**2)


_lm2_bounds: Final = cast(
"Callable[[lmt.ToOrderND, _Tuple2[float]], _FloatND]",
np.vectorize(_lm2_bounds_single, otypes=[float], excluded={1}, signature="()->()"),
_lm2_bounds: Final = np.vectorize(
_lm2_bounds_single,
otypes=[float],
excluded={1},
signature="()->()",
)


Expand All @@ -377,20 +381,20 @@ def l_moment_bounds(
r: lmt.ToOrder0D,
/,
trim: lmt.ToTrim = 0,
scale: float = 1.0,
scale: _Float = 1,
) -> float: ...
@overload
def l_moment_bounds(
r: lmt.ToOrderND,
/,
trim: lmt.ToTrim = 0,
scale: float = 1.0,
scale: _Float = 1,
) -> _FloatND: ...
def l_moment_bounds(
r: lmt.ToOrder,
/,
trim: lmt.ToTrim = 0,
scale: float = 1.0,
scale: _Float = 1,
) -> float | _FloatND:
r"""
Returns the absolute upper bounds $L^{(s,t)}_r$ on L-moments
Expand Down
10 changes: 5 additions & 5 deletions lmo/distributions/_genlambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Final, TypeAlias, TypeVar

import numpy as np
import numpy.typing as npt
import optype.numpy as onp
import scipy.special as sps
from scipy.stats.distributions import rv_continuous

Expand All @@ -29,7 +29,7 @@


_F8: TypeAlias = float | np.float64
_ArrF8: TypeAlias = npt.NDArray[np.float64]
_ArrF8: TypeAlias = onp.ArrayND[np.float64]

_XT = TypeVar("_XT", bound=_F8 | _ArrF8)

Expand Down Expand Up @@ -186,7 +186,7 @@ def _stats(
a, c = 1 + f, 1 - f
b1, d1 = 1 + b, 1 + d

m1 = 0 if b == d and f == 0 else float(lm_genlambda(1, 0, 0, b, d, f).item())
m1: float = 0.0 if b == d and f == 0 else lm_genlambda(1, 0, 0, b, d, f).item()

if b <= -1 / 2 or d <= -1 / 2:
return m1, math.nan, math.nan, math.nan
Expand All @@ -209,7 +209,7 @@ def _stats(
m2 = (
(a / b1) ** 2 / (b1 + b)
+ (c / d1) ** 2 / (d1 + d)
+ 2 * a * c / (b * d) * (1 / (b1 * d1) - sps.beta(b1, d1))
+ 2 * a * c / (b * d) * (1 / (b1 * d1) - sps.beta(b1, d1).item())
)

# Feeling adventurous? You're welcome to contribute these missing
Expand All @@ -229,7 +229,7 @@ def _entropy(self, b: float, d: float, f: float) -> float:

def _l_moment(
self,
r: npt.NDArray[np.intp],
r: onp.ArrayND[lmt.Integer],
b: float,
d: float,
f: float,
Expand Down
Loading

0 comments on commit e2f0143

Please sign in to comment.