Skip to content

Commit

Permalink
Merge pull request #359 from jorenham/bump-dev-deps
Browse files Browse the repository at this point in the history
update the development dependencies (and `optype`)
  • Loading branch information
jorenham authored Nov 29, 2024
2 parents 94399b1 + 9af5960 commit c2ee0be
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ repos:
- id: codespell

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
rev: v0.8.1
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
10 changes: 5 additions & 5 deletions lmo/_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ def l_moment_cov(
- Use the direct (Jacobi) method from Hosking (2015).
"""
_r_max = clean_order(r_max, "r_max")
_trim = cast(tuple[int, int], clean_trim(trim))
_trim = cast("tuple[int, int]", clean_trim(trim))

if any(int(t) != t for t in _trim):
msg = "l_moment_cov does not support fractional trimming (yet)"
Expand Down Expand Up @@ -1585,7 +1585,7 @@ def l_moment_influence(
n = len(x_k)

w_k: onp.Array1D[np.float64] = l_weights(_r, n, (s, t))[-1]
l_r = cast(np.float64, w_k @ x_k)
l_r = cast("np.float64", w_k @ x_k)

def influence_function(x: _T_x, /) -> _T_x:
_x = np.asanyarray(x)
Expand All @@ -1604,7 +1604,7 @@ def influence_function(x: _T_x, /) -> _T_x:

if _x.ndim == 0 and np.isscalar(x):
return out.item()
return cast(_T_x, out)
return cast("_T_x", out)

influence_function.__doc__ = (
f"Empirical L-moment influence function given "
Expand Down Expand Up @@ -1663,7 +1663,7 @@ def l_ratio_influence(
eif_k = l_moment_influence(_x, _s, trim, sort=False, tol=0)

l_r, l_k = cast(
tuple[float, float],
"tuple[float, float]",
(eif_r.l, eif_k.l), # pyright: ignore[reportFunctionMemberAccess]
)
if abs(l_k) <= tol * abs(l_r):
Expand All @@ -1677,7 +1677,7 @@ def influence_function(x: _T_x, /) -> _T_x:
# cheat a bit to avoid `inf - inf = nan` situations
psi_k = np.where(np.isinf(psi_r), 0, eif_k(x))

return cast(_T_x, round0((psi_r - t_r * psi_k) / l_k, tol=tol)[()])
return cast("_T_x", round0((psi_r - t_r * psi_k) / l_k, tol=tol)[()])

influence_function.__doc__ = (
f"Theoretical influence function for L-moment ratio with "
Expand Down
4 changes: 2 additions & 2 deletions lmo/_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def extrema_jacobi(n: int, a: float, b: float) -> tuple[float, float]:
"""
x = peaks_jacobi(n, a, b)
p = eval_sh_jacobi(n, a, b, (x + 1) / 2)
return cast(float, np.min(p)), cast(float, np.max(p))
return cast("float", np.min(p)), cast("float", np.max(p))


def jacobi(
Expand Down Expand Up @@ -388,7 +388,7 @@ def roots(p: PolySeries, /, outside: op.CanBool = False) -> onp.Array1D[np.float
"""
z = p.roots()
x = cast(
onp.Array1D[np.float64],
"onp.Array1D[np.float64]",
z[np.isreal(z)].real if np.isrealobj(p.domain) and not np.isrealobj(z) else z,
)

Expand Down
18 changes: 9 additions & 9 deletions lmo/contrib/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def l_moment(
"""
out = _l_moment(self, r, trim=trim, **kwargs)
if np.isscalar(out):
return cast(float, out)
return cast("float", out)

return pd.Series(
cast(npt.NDArray[np.float64], out),
cast("npt.NDArray[np.float64]", out),
index=pd.Index(np.asarray(r), name="r"),
dtype=float,
copy=False,
Expand All @@ -185,10 +185,10 @@ def l_ratio(
rk = np.stack(np.broadcast_arrays(np.asarray(r), np.asarray(k)))
out = moments_to_ratio(rk, _l_moment(self, rk, trim=trim, **kwargs))
if rk.ndim == 1:
return cast(float, out)
return cast("float", out)

return pd.Series(
cast(npt.NDArray[np.float64], out),
cast("npt.NDArray[np.float64]", out),
index=_ratio_index(rk),
dtype=float,
copy=False,
Expand Down Expand Up @@ -224,7 +224,7 @@ def l_loc(
Returns:
out: A scalar.
"""
return cast(float, _l_moment(self, 1, trim, **kwargs))
return cast("float", _l_moment(self, 1, trim, **kwargs))

def l_scale(
self,
Expand All @@ -237,7 +237,7 @@ def l_scale(
Returns:
out: A scalar.
"""
return cast(float, _l_moment(self, 2, trim, **kwargs))
return cast("float", _l_moment(self, 2, trim, **kwargs))

def l_variation(
self,
Expand All @@ -250,7 +250,7 @@ def l_variation(
Returns:
out: A scalar.
"""
return cast(float, _l_ratio(self, 2, 1, trim, **kwargs))
return cast("float", _l_ratio(self, 2, 1, trim, **kwargs))

def l_skew(
self,
Expand All @@ -263,7 +263,7 @@ def l_skew(
Returns:
out: A scalar.
"""
return cast(float, _l_ratio(self, 3, 2, trim, **kwargs))
return cast("float", _l_ratio(self, 3, 2, trim, **kwargs))

def l_kurtosis(
self,
Expand All @@ -276,7 +276,7 @@ def l_kurtosis(
Returns:
out: A scalar.
"""
return cast(float, _l_ratio(self, 4, 2, trim, **kwargs))
return cast("float", _l_ratio(self, 4, 2, trim, **kwargs))

l_kurt = l_kurtosis

Expand Down
6 changes: 3 additions & 3 deletions lmo/contrib/scipy_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def _l_gmm_error(
raise ValueError(msg)

err = l_data - l_dist
return cast(float, err @ weights @ err)
return cast("float", err @ weights @ err)

@overload
def l_fit(
Expand Down Expand Up @@ -1473,5 +1473,5 @@ def install() -> None:
to the `scipy.stats.rv_generic` and `scipy.stats.lmt.rv_frozen`
types, respectively.
"""
l_rv_generic.patch(cast(type[object], lmt.rv_continuous.__base__))
l_rv_frozen.patch(cast(type[object], lmt.rv_frozen))
l_rv_generic.patch(cast("type[object]", lmt.rv_continuous.__base__))
l_rv_frozen.patch(cast("type[object]", lmt.rv_frozen))
9 changes: 5 additions & 4 deletions lmo/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import math
import sys
import warnings
from collections.abc import Callable
from math import lgamma
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -35,6 +34,8 @@
from .special import fpow

if TYPE_CHECKING:
from collections.abc import Callable

from .contrib.scipy_stats import l_rv_generic

__all__ = (
Expand Down Expand Up @@ -366,7 +367,7 @@ def _lm2_bounds_single(r: int, trim: _Tuple2[float]) -> float:


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

Expand Down Expand Up @@ -614,7 +615,7 @@ def l_ratio_bounds(

_cache: dict[int, _Tuple2[float]] = {}
for i, ri in np.ndenumerate(_r):
_ri = cast(int, ri)
_ri = cast("int", ri)
if _ri in _cache:
t_min[i], t_max[i] = _cache[_ri]

Expand Down Expand Up @@ -747,7 +748,7 @@ def obj(r: _FloatND) -> float:

res = minimize(obj, bounds=[(rho_min, rho_max)], x0=[rho_min], method="COBYLA")

rho = cast(float, res.x[0])
rho = cast("float", res.x[0])
if rho <= _MIN_RHO or influence_fn(-rho) or influence_fn(rho):
return np.nan

Expand Down
6 changes: 3 additions & 3 deletions lmo/distributions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[Distributions - Wakeby](../distributions.md#wakeby).
"""
else:
wakeby: Final = cast(lmt.rv_continuous, wakeby_gen(a=0.0, name="wakeby"))
wakeby: Final = cast("lmt.rv_continuous", wakeby_gen(a=0.0, name="wakeby"))

# mkdocstring workaround
if not TYPE_CHECKING:
Expand All @@ -57,7 +57,7 @@
"""
else:
kumaraswamy: Final = cast(
lmt.rv_continuous,
"lmt.rv_continuous",
kumaraswamy_gen(a=0.0, b=1.0, name="kumaraswamy"),
)

Expand All @@ -77,4 +77,4 @@
[Distributions - GLD](../distributions.md#gld).
"""
else:
genlambda: Final = cast(lmt.rv_continuous, genlambda_gen(name="genlambda"))
genlambda: Final = cast("lmt.rv_continuous", genlambda_gen(name="genlambda"))
2 changes: 1 addition & 1 deletion lmo/inference/_l_gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def AIC(self) -> float: # noqa: N802
identification](https://doi.org/10.1109%2FTAC.1974.1100705)
"""
return 2 * (self.n_arg - np.log(cast(float, self.j_test.pvalue)))
return 2 * (self.n_arg - np.log(cast("float", self.j_test.pvalue)))

@property
def AICc(self) -> float: # noqa: N802
Expand Down
2 changes: 1 addition & 1 deletion lmo/theoretical/_f_to_lm_eif.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def influence(x: _T_x, /) -> _T_x:
# cheat a bit and replace 0 * inf by 0, ensuring convergence if s or t
alpha = w * eval_sh_jacobi(_r - 1, t, s, q) * np.where(w, _x, 0)

return cast(_T_x, round0(alpha - lm, tol)[()])
return cast("_T_x", round0(alpha - lm, tol)[()])

influence.__doc__ = (
f"Theoretical influence function for L-moment with {r=} and {trim=}."
Expand Down
16 changes: 7 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"numpy>=1.24",
"scipy>=1.10",
"scipy-stubs>=1.14.1.4",
"optype[numpy]>=0.7.1",
"optype[numpy]>=0.7.2",
]

[project.optional-dependencies]
Expand All @@ -53,7 +53,7 @@ Funding = "https://github.com/sponsors/jorenham"

[dependency-groups]
debug = [
"ipython>=8.29.0",
"ipython>=8.30.0",
"ipykernel>=6.29.5",
"line_profiler>=4.1.3; python_version<'3.13'",
"matplotlib>=3.9.2",
Expand All @@ -65,7 +65,7 @@ docs = [
"mkdocs-git-revision-date-localized-plugin>=1.3.0",
"mkdocs-include-markdown-plugin>=7.1.1",
"mkdocs-jupyter>=0.25.1",
"mkdocs-material>=9.5.45",
"mkdocs-material>=9.5.46",
"mkdocs-minify-plugin>=0.8.0",
"mkdocstrings[python]>=0.27.0",
]
Expand All @@ -76,12 +76,12 @@ pandas = [
dev = [
"blacken-docs>=1.19.1",
"codespell>=2.3.0",
"hypothesis[numpy]>=6.119.3",
"hypothesis[numpy]>=6.121.2",
"pre-commit>=4.0.1",
"basedpyright>=1.21.1",
"basedpyright>=1.22.0",
"pytest>=8.3.3",
"pytest-doctestplus>=1.2.1",
"ruff>=0.7.4",
"pytest-doctestplus>=1.3.0",
"ruff>=0.8.1",
"sp-repo-review[cli]>=2024.8.19",
"tox>=4.23.2",
]
Expand Down Expand Up @@ -184,8 +184,6 @@ ignore = [
"D205", # blank-line-after-summary
"D212", # multi-line-summary-first-line
# flake8-annotations
"ANN101", # missing-type-self (deprecated)
"ANN102", # missing-type-cls (deprecated)
"ANN401", # any-type
# flake8-bandit
"S101", # assert
Expand Down
12 changes: 6 additions & 6 deletions tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def test_l_poly_eq_uniform(trim: lmt.ToTrim):
p0 = x0 = np.linspace(0, 1)

X = cast(Any, uniform())
X = cast("Any", uniform())
X_hat = l_poly(X.l_moment([1, 2], trim=trim), trim=trim)

t4 = X.l_stats(trim=trim)
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_l_poly_eq_uniform(trim: lmt.ToTrim):
],
)
def test_wakeby(b: float, d: float, f: float):
X = cast(Any, wakeby(b, d, f))
X = cast("Any", wakeby(b, d, f))

assert X.cdf(X.support()[0]) == 0
assert X.ppf(0) == X.support()[0]
Expand Down Expand Up @@ -100,8 +100,8 @@ def test_wakeby(b: float, d: float, f: float):

@pytest.mark.parametrize("lam", [0, 0.14, 1, -1])
def test_genlambda_tukeylamba(lam: float):
X0 = cast(Any, tukeylambda(lam))
X = cast(Any, genlambda(lam, lam, 0))
X0 = cast("Any", tukeylambda(lam))
X = cast("Any", genlambda(lam, lam, 0))

x0 = X0.ppf(Q)
x = X.ppf(Q)
Expand All @@ -110,7 +110,7 @@ def test_genlambda_tukeylamba(lam: float):
assert_allclose(x, x0)

_pp = cast(
npt.NDArray[np.float64],
"npt.NDArray[np.float64]",
np.linspace(X0.ppf(0.05), X0.ppf(0.95), 100),
)
u0 = X0.cdf(_pp)
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_genlambda_tukeylamba(lam: float):
@pytest.mark.parametrize("d", [-1.95, 0, 1.95], ids="d={}".format)
@pytest.mark.parametrize("b", [-1.95, 0, 1.95], ids="b={}".format)
def test_genlambda(b: float, d: float, f: float):
X = cast(Any, genlambda(b, d, f))
X = cast("Any", genlambda(b, d, f))

assert X.cdf(X.support()[0]) == 0
assert X.ppf(0) == X.support()[0]
Expand Down
14 changes: 8 additions & 6 deletions tests/test_theoretical.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import functools
from collections.abc import Callable
from typing import cast
from typing import TYPE_CHECKING, cast

import numpy as np
import pytest
Expand All @@ -23,10 +22,13 @@
qdf_from_l_moments,
)

if TYPE_CHECKING:
from collections.abc import Callable

assert_allclose = functools.partial(_assert_allclose, rtol=1e-6, atol=1e-8)

norm_cdf = cast(Callable[[float], float], ndtr)
norm_ppf = cast(Callable[[float], float], ndtri)
norm_cdf = cast("Callable[[float], float]", ndtr)
norm_ppf = cast("Callable[[float], float]", ndtri)


@np.errstate(over="ignore", under="ignore")
Expand Down Expand Up @@ -267,7 +269,7 @@ def test_ls_cov_uniform():
trim=st.tuples(st.integers(0, 1), st.integers(0, 3)),
)
def test_ppf_from_l_moments_identity(
ppf: Callable[[float], float],
ppf: "Callable[[float], float]",
trim: tuple[int, int] | int,
):
rmax = 8
Expand All @@ -291,7 +293,7 @@ def test_ppf_from_l_moments_identity(
trim=st.tuples(st.integers(0, 1), st.integers(0, 3)),
)
def test_qdf_from_l_moments_identity(
qdf: Callable[[float], float],
qdf: "Callable[[float], float]",
trim: tuple[int, int] | int,
):
rmax = 8
Expand Down
Loading

0 comments on commit c2ee0be

Please sign in to comment.