Skip to content

Commit

Permalink
use codespell and pygrep hooks, replace isort with ruff, address bugb…
Browse files Browse the repository at this point in the history
…ear issues
  • Loading branch information
Zeitsperre committed Sep 9, 2024
1 parent 521fbeb commit 69f4e3d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ updates:
directory: /
schedule:
interval: monthly
groups:
actions:
patterns:
- "*"

- package-ecosystem: pip
directory: /
schedule:
interval: monthly
groups:
python:
patterns:
- "*"
23 changes: 16 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ repos:
- id: yamllint
args: [ '--config-file=.yamllint.yaml' ]
exclude: conda-recipe/meta.yaml
- repo: https://github.com/psf/black
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-no-eval
- id: python-no-log-warn
# - id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
Expand All @@ -35,22 +43,23 @@ repos:
hooks:
- id: flake8
args: [ '--config=.flake8' ]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: [ '--settings-file=pyproject.toml' ]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
hooks:
- id: ruff
args: [ '--fix' ]
args: [ '--fix', '--show-fixes' ]
# - id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies: [ 'tomli' ]
- repo: https://github.com/keewis/blackdoc
rev: v0.3.9
hooks:
- id: blackdoc
additional_dependencies: [ 'black==24.8.0' ]
- id: blackdoc-autoupdate-black
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
2 changes: 1 addition & 1 deletion docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Example: Calculate the Negative Log Likelihood of a Gamma distribution with par
Other statistical methods
-------------------------

The :mod:`lmoments3.stats` module provides some additional statistical parametes to evaluate fitting of data to
The :mod:`lmoments3.stats` module provides some additional statistical parameters to evaluate fitting of data to
distribution function.

:func:`AIC(data, distr_name, distr_paras)`
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,9 @@ include = [
]
exclude = [".*", "conda-recipe/**", "docs/build/**"]

[tool.isort]
profile = "black"
py_version = 38
append_only = true

[tool.ruff]
src = ["lmoments3"]
line-length = 150
target-version = "py38"
exclude = [
".eggs",
".git",
Expand All @@ -128,12 +122,14 @@ ignore = [
]
preview = true
select = [
"B", # bugbear
"BLE", # blind-except
"C90", # mccabe-complexity
"D", # docstrings
"E", # pycodestyle errors
"FLY002", # static-join-to-fstring
"G", # logging-format
"I", # import-order
"N", # naming conventions
"PERF", # iterator performance
"PTH", # pathlib
Expand Down
10 changes: 5 additions & 5 deletions src/lmoments3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def _samlmularge(x, nmom=5):
x = np.asarray(x, dtype=np.float64)
n = len(x)
x = np.sort(x)
except ValueError:
raise ValueError("Input data to estimate L-moments must be numeric.")
except ValueError as err:
raise ValueError("Input data to estimate L-moments must be numeric.") from err

if nmom <= 0:
raise ValueError("Invalid number of sample L-moments")
Expand All @@ -111,7 +111,7 @@ def _samlmularge(x, nmom=5):
xtrans = []
for i in range(0, n):
coeftemp = []
for j in range(0, mom):
for _j in range(0, mom):
coeftemp.append(1)

for j in range(0, mom - 1):
Expand Down Expand Up @@ -140,8 +140,8 @@ def _samlmusmall(x, nmom=5):
x = np.asarray(x, dtype=np.float64)
n = len(x)
x = np.sort(x)
except ValueError:
raise ValueError("Input data to estimate L-moments must be numeric.")
except ValueError as err:
raise ValueError("Input data to estimate L-moments must be numeric.") from err

if nmom <= 0 or nmom > 5:
raise ValueError("Invalid number of sample L-moments")
Expand Down
7 changes: 4 additions & 3 deletions src/lmoments3/distr.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import lmoments3 as lm


try:
# Scipy >= 1.9
from scipy.stats._distn_infrastructure import rv_continuous_frozen
Expand Down Expand Up @@ -622,7 +623,7 @@ def _lmom_fit(self, lmom_ratios):
# Newton-Raphson Iteration
for it in range(1, MAXIT + 1):
Success = 0
for i in range(1, MAXSR + 1):
for _ in range(1, MAXSR + 1):
if G > OFLGAM:
raise Exception("Failed to converge")
if H > 0:
Expand Down Expand Up @@ -959,7 +960,7 @@ def _cdfwak(self, x, para): # noqa: C901
if D > 0:
Z = math.log((x - XI) * D / C + 1) / D

for IT in range(1, MAXIT + 1):
for _IT in range(1, MAXIT + 1):
EB = 0
BZ = -B * Z
if BZ >= UFL:
Expand Down Expand Up @@ -1321,7 +1322,7 @@ def _lmom_fit(self, lmom_ratios):
G = 1 - math.log(1 + T3) / DL2

T0 = (T3 + 3) * 0.5
for IT in range(1, maxit):
for _IT in range(1, maxit):
X2 = 2**-G
X3 = 3**-G
XX2 = 1 - X2
Expand Down
6 changes: 3 additions & 3 deletions src/lmoments3/tests/test_samlmu_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def tearDown(self):

def test_n50_nmom3(self):
start_i = 0
for i in range(10000):
for _i in range(10000):
l1, l2, t3 = lm.lmom_ratios(self.record[start_i : start_i + self.n], nmom=3)
assert l2 / l1
start_i += self.n

def test_n50_nmom4(self):
start_i = 0
for i in range(10000):
for _i in range(10000):
l1, l2, t3, t4 = lm.lmom_ratios(
self.record[start_i : start_i + self.n], nmom=4
)
Expand All @@ -49,5 +49,5 @@ def tearDown(self):
def test_n50(self):
n = 50
kappa_distr = distr.kap(loc=-0.7, scale=2.6, k=0.9, h=1.6)
for i in range(10000):
for _i in range(10000):
kappa_distr.ppf(np.random.random(n))

0 comments on commit 69f4e3d

Please sign in to comment.