Skip to content

update development dependencies #392

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

Merged
merged 2 commits into from
Mar 17, 2025
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
2 changes: 1 addition & 1 deletion lmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import numpy as np

if np.__version__.startswith("2."):
np.set_printoptions(legacy="1.25") # pyright: ignore[reportArgumentType]
np.set_printoptions(legacy="1.25")

del np

Expand Down
30 changes: 15 additions & 15 deletions lmo/_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def __call__(self, x: onp.ToFloatND, /) -> _FloatND: ...


def _l_weights_pwm(
r: _OrderT,
n: _SizeT,
r: int,
n: int,
/,
trim: tuple[int, int],
*,
dtype: _ToDType[_FloatT],
) -> onp.Array[tuple[_OrderT, _SizeT], _FloatT]:
) -> onp.Array2D[_FloatT]:
s, t = trim
r0 = r + s + t
dtype = np.dtype(dtype)
Expand All @@ -106,13 +106,13 @@ def _l_weights_pwm(


def _l_weights_ostat(
r: _OrderT,
n: _SizeT,
r: int,
n: int,
/,
trim: tuple[int, int] | tuple[float, float],
*,
dtype: _ToDType[_FloatT],
) -> onp.Array[tuple[_OrderT, _SizeT], _FloatT]:
) -> onp.Array2D[_FloatT]:
assert r >= 1, r

s, t = trim
Expand Down Expand Up @@ -344,18 +344,15 @@ def l_moment(
dtype: _ToDType[_FloatT],
**kwds: Unpack[lmt.LMomentOptions],
) -> onp.ArrayND[_FloatT]: ...
def l_moment(
def l_moment( # pyright
a: onp.ToFloatND,
r: lmt.ToOrder,
/,
trim: lmt.ToTrim = 0,
*,
axis: int | None = None,
dtype: _ToDType[npc.floating] = np.float64,
fweights: lmt.ToFWeights | None = None,
aweights: lmt.ToAWeights | None = None,
sort: lmt.SortKind | bool = True,
cache: bool | None = None,
**kwds: Unpack[lmt.LMomentOptions],
) -> float | _FloatND:
r"""
Estimates the generalized trimmed L-moment $\lambda^{(s, t)}_r$ from
Expand Down Expand Up @@ -460,9 +457,9 @@ def l_moment(
a,
axis=axis,
dtype=dtype,
fweights=fweights,
aweights=aweights,
sort=sort,
fweights=kwds.pop("fweights", None),
aweights=kwds.pop("aweights", None),
sort=kwds.pop("sort", True),
)
x_k = ensure_axis_at(x_k, axis, -1)
n = x_k.shape[-1]
Expand All @@ -482,7 +479,10 @@ def l_moment(
if t:
x_k[..., -t:] = np.nan_to_num(x_k[..., -t:], nan=np.nan)

l_r = np.inner(l_weights(r_max, n, st, dtype=dtype, cache=cache), x_k)
l_r = np.inner(
l_weights(r_max, n, st, dtype=dtype, cache=kwds.pop("cache", None)),
x_k,
)

out: npc.floating | _FloatND
if r_min > 0:
Expand Down
2 changes: 1 addition & 1 deletion lmo/distributions/_wakeby.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _fitstart(
@override
def _pdf(self, /, x: _XT, b: float, d: float, f: float) -> _XT:
# application of the inverse function theorem
return 1 / self._qdf(self._cdf(x, b, d, f), b, d, f) # pyright: ignore[reportReturnType]
return 1 / self._qdf(self._cdf(x, b, d, f), b, d, f)

@override
def _cdf(self, /, x: _XT, b: float, d: float, f: float) -> _XT:
Expand Down
31 changes: 15 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,35 @@ Funding = "https://github.com/sponsors/jorenham"

[dependency-groups]
debug = [
"ipython>=8.31.0",
"ipython>=9.0.2",
"ipykernel>=6.29.5",
"line_profiler>=4.2.0",
"matplotlib>=3.10.0",
"matplotlib>=3.10.1",
"typing-extensions>=4.12.2",
]
docs = [
"mkdocs>=1.6.1",
"mkdocs-bibtex>=2.16.2",
"mkdocs-git-revision-date-localized-plugin>=1.3.0",
"mkdocs-include-markdown-plugin>=7.1.2",
"mkdocs-bibtex>=4.2.3",
"mkdocs-git-revision-date-localized-plugin>=1.4.5",
"mkdocs-include-markdown-plugin>=7.1.5",
"mkdocs-jupyter>=0.25.1",
"mkdocs-material>=9.5.49",
"mkdocs-material>=9.6.9",
"mkdocs-minify-plugin>=0.8.0",
"mkdocstrings[python]>=0.27.0",
"mkdocstrings[python]>=0.29.0",
]
pandas = [
"pandas>=2.2.3",
"pandas-stubs>=2.2.3.241126",
"pandas-stubs>=2.2.3.250308",
]
dev = [
"blacken-docs>=1.19.1",
"codespell>=2.3.0",
"hypothesis[numpy]>=6.123.17",
"basedpyright>=1.24.0",
"pytest>=8.3.4",
"pytest-doctestplus>=1.3.0",
"ruff>=0.9.1",
"sp-repo-review[cli]>=2024.8.19",
"tox>=4.23.2",
"codespell>=2.4.1",
"hypothesis[numpy]>=6.129.3",
"basedpyright>=1.28.1",
"pytest>=8.3.5",
"pytest-doctestplus>=1.4.0",
"ruff>=0.11.0",
"sp-repo-review[cli]>=2025.1.22",
]

[tool.uv]
Expand Down
28 changes: 20 additions & 8 deletions tests/test_multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,50 @@


@given(r=st_r, n=st_n, trim=st_trim)
def test_l_comoment_empty(r: int, n: int, trim: tuple[int, int]):
def test_l_comoment_empty(r: int, n: int, trim: tuple[int, int]) -> None:
l_00 = lmo.l_comoment(np.empty((0, n)), r, trim)

assert l_00.shape == (0, 0)


@given(a=st_a, trim=st_trim)
def test_l_comoment_zero(a: npt.NDArray[np.float64], trim: tuple[int, int]):
def test_l_comoment_zero(a: npt.NDArray[np.float64], trim: tuple[int, int]) -> None:
l_aa = lmo.l_comoment(a, 0, trim)

assert l_aa.shape == (len(a), len(a))
assert np.array_equal(l_aa, np.eye(len(a)))


@given(a=st_a, r=st_r, trim=st_trim)
def test_tl_comoment_rowvar(a: npt.NDArray[np.float64], r: int, trim: tuple[int, int]):
def test_tl_comoment_rowvar(
a: npt.NDArray[np.float64],
r: int,
trim: tuple[int, int],
) -> None:
l_aa = lmo.l_comoment(a, r, trim)
l_aa_t = lmo.l_comoment(a.T, r, trim, rowvar=False)

assert np.array_equal(l_aa, l_aa_t)


@given(a=st_a, r=st_r, trim=st_trim)
def test_tl_comoment_diag(a: npt.NDArray[np.float64], r: int, trim: tuple[int, int]):
def test_tl_comoment_diag(
a: npt.NDArray[np.float64],
r: int,
trim: tuple[int, int],
) -> None:
l_a = lmo.l_moment(a, r, trim, axis=1)
L_aa = lmo.l_comoment(a, r, trim)

assert np.allclose(L_aa.diagonal(), l_a)


@given(a=st_a, r=st_r, trim=st_trim)
def test_l_comoment_rowwise(a: npt.NDArray[np.float64], r: int, trim: tuple[int, int]):
def test_l_comoment_rowwise(
a: npt.NDArray[np.float64],
r: int,
trim: tuple[int, int],
) -> None:
l_a = lmo.l_moment(a, r, trim, axis=1)

def func(a_m: npt.NDArray[np.float64]):
Expand All @@ -77,17 +89,17 @@ def func(a_m: npt.NDArray[np.float64]):


@given(a=st_a)
def test_l_coloc_mean(a: npt.NDArray[np.float64]):
def test_l_coloc_mean(a: npt.NDArray[np.float64]) -> None:
m_a = a.mean(1)
l_aa = lmo.l_coloc(a)
l_a0 = l_aa[:, 0]

assert np.allclose(l_a0, m_a, atol=1e-3, rtol=1e-3)


@settings(deadline=timedelta(seconds=1))
@settings(deadline=timedelta(seconds=1)) # pyright: ignore[reportArgumentType]
@given(a=st_a_unique)
def test_l_corr_standard(a: npt.NDArray[np.float64]):
def test_l_corr_standard(a: npt.NDArray[np.float64]) -> None:
r_aa = lmo.l_corr(a)

assert np.all(r_aa.diagonal() == 1)
Expand Down
28 changes: 14 additions & 14 deletions tests/test_theoretical.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def uniform_qdf(p: float) -> float:

# @given(a=st.floats(0.1, 10))
@pytest.mark.parametrize("a", [0.1, 10])
def test_lm_expon(a: float):
def test_lm_expon(a: float) -> None:
l_stats = np.array([a, a / 2, 1 / 3, 1 / 6])
r = np.arange(5)

Expand All @@ -117,7 +117,7 @@ def test_lm_expon(a: float):
assert_allclose(l_stats_cdf, l_stats, rtol=5e-7)


def test_lm_normal():
def test_lm_normal() -> None:
from statistics import NormalDist

mu, sigma = 100, 15
Expand All @@ -139,7 +139,7 @@ def test_lm_normal():
assert_allclose(l_qdf, lr[1:])


def test_tlm_normal():
def test_tlm_normal() -> None:
from statistics import NormalDist

mu, sigma = 100, 15
Expand All @@ -165,7 +165,7 @@ def test_tlm_normal():
assert_allclose(tl_qdf, tl[1:])


def test_tlm_cauchy():
def test_tlm_cauchy() -> None:
r = [1, 2, 3, 4]

z3 = zeta(3)
Expand All @@ -183,7 +183,7 @@ def test_tlm_cauchy():


@given(a=st.floats(0.1, 10))
def test_llm_expon(a: float):
def test_llm_expon(a: float) -> None:
r = [1, 2, 3, 4]
lr = a * np.array([1, 1 / 2, 1 / 9, 1 / 24]) / 2

Expand All @@ -201,7 +201,7 @@ def test_llm_expon(a: float):
assert_allclose(l_qdf, lr[1:])


def test_lm_cov_uniform():
def test_lm_cov_uniform() -> None:
k4 = (
np.array([
[1 / 2, 0, -1 / 10, 0],
Expand All @@ -216,7 +216,7 @@ def test_lm_cov_uniform():
assert_allclose(k4, k4_hat)


def test_lm_cov_expon():
def test_lm_cov_expon() -> None:
k3 = np.array([
[1, 1 / 2, 1 / 6],
[1 / 2, 1 / 3, 1 / 6],
Expand All @@ -227,7 +227,7 @@ def test_lm_cov_expon():
assert_allclose(k3, k3_hat)


def test_llm_cov_expon():
def test_llm_cov_expon() -> None:
k3 = np.array([
[1 / 3, 1 / 8, 0],
[1 / 8, 3 / 40, 1 / 60],
Expand All @@ -239,7 +239,7 @@ def test_llm_cov_expon():


@np.errstate(over="ignore", under="ignore")
def test_lm_cov_loc_scale_invariant():
def test_lm_cov_loc_scale_invariant() -> None:
k4_hat = l_moment_cov_from_cdf(gumbel_cdf, 4, trim=(0, 1))
k4_hat_r = l_moment_cov_from_cdf(
functools.partial(gumbel_cdf, loc=5, scale=3),
Expand All @@ -249,7 +249,7 @@ def test_lm_cov_loc_scale_invariant():
assert_allclose(k4_hat, k4_hat_r / 9)


def test_ls_cov_uniform():
def test_ls_cov_uniform() -> None:
k4 = np.array([
[1 / 12, 0, -1 / 10, 0],
[0, 1 / 180, 0, -1 / 70],
Expand All @@ -261,7 +261,7 @@ def test_ls_cov_uniform():
assert_allclose(k4, k4_hat)


@settings(deadline=1_000)
@settings(deadline=1_000) # pyright: ignore[reportArgumentType]
@given(
ppf=st.one_of(
*map(st.just, [uniform_ppf, norm_ppf, gumbel_ppf, rayleigh_ppf, expon_ppf])
Expand All @@ -271,7 +271,7 @@ def test_ls_cov_uniform():
def test_ppf_from_l_moments_identity(
ppf: "Callable[[float], float]",
trim: tuple[int, int] | int,
):
) -> None:
rmax = 8
r = np.mgrid[1 : rmax + 1]
l_r = l_moment_from_ppf(ppf, r, trim)
Expand All @@ -285,7 +285,7 @@ def test_ppf_from_l_moments_identity(
assert_allclose(l_0_hat, l_0)


@settings(deadline=1_000)
@settings(deadline=1_000) # pyright: ignore[reportArgumentType]
@given(
qdf=st.one_of(
*map(st.just, [uniform_qdf, norm_qdf, gumbel_qdf, rayleigh_qdf, expon_qdf])
Expand All @@ -295,7 +295,7 @@ def test_ppf_from_l_moments_identity(
def test_qdf_from_l_moments_identity(
qdf: "Callable[[float], float]",
trim: tuple[int, int] | int,
):
) -> None:
rmax = 8
r = np.mgrid[2 : rmax + 1]
l_r = l_moment_from_qdf(qdf, r, trim)
Expand Down
Loading