Skip to content

Commit

Permalink
Merge pull request #332 from jorenham/black-style
Browse files Browse the repository at this point in the history
black style
  • Loading branch information
jorenham authored Oct 15, 2024
2 parents 7570d6d + 5de025a commit 46a9329
Show file tree
Hide file tree
Showing 58 changed files with 1,049 additions and 1,208 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: scientific-python/repo-review@v0.11.2
with:
plugins: sp-repo-review

- name: install poetry
run: |
pipx install poetry
Expand All @@ -44,17 +40,30 @@ jobs:
- name: poetry install
run: poetry install --without debug,docs --all-extras

- name: repo-review
run: poetry run repo-review .

- name: markdownlint
uses: DavidAnson/markdownlint-cli2-action@v17
with:
config: ".markdownlint.yaml"
globs: "*.md"

- name: blacken-docs
run: git ls-files -z -- '*.md' | xargs -0 poetry run blacken-docs

- name: codespell
run: poetry run codespell .

- name: ruff check
run: poetry run ruff check --output-format=github
run: |
poetry run ruff check --output-format=github
poetry run ruff format --check
- name: basedpyright
run: poetry run basedpyright

- name: basedpyright --verifytypes
run: poetry run basedpyright --ignoreexternal --verifytypes optype
run: |
poetry run basedpyright
poetry run basedpyright --ignoreexternal --verifytypes lmo
test:
timeout-minutes: 20
Expand Down
2 changes: 2 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ default: true
no-hard-tabs: true
MD007:
indent: 4
MD013:
line_length: 88
MD033:
allowed_elements:
- "br"
Expand Down
12 changes: 10 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ci:
- poetry-check
- codespell
- ruff
- ruff-format
- basedpyright
- basedpyright-verifytypes

Expand Down Expand Up @@ -50,16 +51,22 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.3.3"
rev: v3.3.3
hooks:
- id: prettier
types_or: [yaml, html, css, scss, javascript, json]

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
rev: v0.42.0
hooks:
- id: markdownlint

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.0
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]

- repo: https://github.com/python-poetry/poetry
rev: 1.8.4
hooks:
Expand All @@ -75,6 +82,7 @@ repos:
hooks:
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format

- repo: local
hooks:
Expand Down
12 changes: 5 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.rulers": [79, 130]
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modificationsIfAvailable",
"editor.formatOnType": true
},
"[bibtex]": {
"editor.rulers": []
},
"[markdown]": {
"editor.rulers": [80]
},
"[markdown_latex_combined]": {
"editor.rulers": [80]
},
"editor.rulers": [88],
"markdown.extension.completion.root": "docs",
"PandocCiter.DefaultBib": "docs/refs.bib",
"PandocCiter.DefaultBibs": ["docs"],
Expand Down
101 changes: 63 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@

# Lmo - Trimmed L-moments and L-comoments

![Lmo - License][IMG-BSD]
[![Lmo - PyPI][IMG-PYPI]](https://pypi.org/project/Lmo/)
[![Lmo - Versions][IMG-VER]](https://github.com/jorenham/Lmo)
[![Lmo - SPEC 0][IMG-SPEC0]](https://scientific-python.org/specs/spec-0000/)
![Lmo - CI][IMG-CI]
[![Lmo - Pre-commit][IMG-PC]](https://github.com/pre-commit/pre-commit)
[![Lmo - Ruff][IMG-RUFF]](https://github.com/astral-sh/ruff)
[![Lmo - BassedPyright][IMG-BPR]](https://detachhead.github.io/basedpyright)

[IMG-CI]: https://img.shields.io/github/actions/workflow/status/jorenham/Lmo/ci.yml?branch=master
[IMG-BSD]: https://img.shields.io/github/license/jorenham/Lmo
[IMG-PYPI]: https://img.shields.io/pypi/v/Lmo
[IMG-VER]: https://img.shields.io/pypi/pyversions/Lmo
[IMG-pC]: https://img.shields.io/badge/pre--commit-enabled-orange?logo=pre-commit
[IMG-RUFF]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
[IMG-BPR]: https://img.shields.io/badge/basedpyright-checked-42b983
[IMG-SPEC0]: https://img.shields.io/badge/SPEC-0-green?labelColor=%23004811&color=%235CA038
[![Lmo - PyPI][IMG-PYPI]][PYPI]
[![Lmo - Python versions][IMG-PY]][REPO]
[![Lmo - SPEC 0][IMG-SPEC0]][SPEC0]
[![Lmo - BSD License][IMG-BSD]][BSD]
[![Lmo - CI][IMG-CI]][CI]
[![Lmo - pre-commit][IMG-PC]][PC]
[![Lmo - ruff][IMG-RUFF]][RUFF]
[![Lmo - bassedpyright][IMG-BPR]][BPR]

Unlike the legacy
[product-moments](https://wikipedia.org/wiki/Moment_(mathematics)), the
Expand All @@ -40,7 +31,7 @@ So Lmo is as fast as sorting your samples (in terms of time-complexity).
- Goodness-of-fit test, using L-moment or L-moment ratio's.
- Exact (co)variance structure of the sample- and population L-moments.
- Theoretical & empirical influence functions of L-moments & L-ratio's.
- Complete [docs](https://jorenham.github.io/Lmo/), including detailed API
- Complete [docs][DOCS], including detailed API
reference with usage examples and with mathematical $\TeX$ definitions.
- Clean Pythonic syntax for ease of use.
- Vectorized functions for very fast fitting.
Expand All @@ -52,33 +43,54 @@ reference with usage examples and with mathematical $\TeX$ definitions.
Even if your data is pathological like
[Cauchy](https://wikipedia.org/wiki/Cauchy_distribution), and the L-moments
are not defined, the trimmed L-moments (TL-moments) can be used instead.
Let's calculate the TL-location and TL-scale of a small amount of samples:

Let's calculate the first two TL-moments (the TL-location and the TL-scale) of a small
amount of samples drawn from the standard Cauchy distribution:

```pycon
>>> import numpy as np
>>> import lmo
>>> rng = np.random.default_rng(1980)
>>> x = rng.standard_cauchy(96) # pickle me, Lmo
>>> lmo.l_moment(x, [1, 2], trim=(1, 1)).
>>> data = rng.standard_cauchy(96)
>>> lmo.l_moment(data, [1, 2], trim=1)
array([-0.17937038, 0.68287665])
```

Now compare with the theoretical standard Cauchy TL-moments:
Compared with the theoretical standard Cauchy TL-moments, that pretty close!

```pycon
>>> from scipy.stats import cauchy
>>> cauchy.l_moment([1, 2], trim=(1, 1))
>>> cauchy.l_moment([1, 2], trim=1)
array([0. , 0.69782723])
```

Now let's try this again using the first two conventional moments, i.e. the mean
and the standard deviation:

```pycon
>>> from scipy.stats import moment
>>> np.r_[data.mean(), data.std()]
array([-1.7113441 , 19.57350731])
```

So even though the `data` was drawn from the *standard* Cauchy distribution, we can
immediately see that this look standard at all.

The reason is that the Cauchy distribution doesn't have a mean or standard
deviation:

```pycon
>>> np.r_[cauchy.mean(), cauchy.std()]
array([nan, nan])
```

---

See the [documentation](https://jorenham.github.io/Lmo/) for more examples and
the API reference.
See the [documentation][DOCS] for more examples and the API reference.

## Installation

Lmo is available on [PyPI](https://pypi.org/project/Lmo/), and can be installed
Lmo is available on [PyPI][PYPI], and can be installed
with:

```shell
Expand Down Expand Up @@ -116,23 +128,36 @@ Additionally, Lmo supports the following optional packages:

See [SPEC 0][SPEC0] for more information.

## Foundational Literature

- [*J.R.M. Hosking* (1990) – L-moments: Analysis and Estimation of Distributions using Linear Combinations of Order Statistics](https://doi.org/10.1111/j.2517-6161.1990.tb01775.x)
- [*E.A.H. Elamir & A.H. Seheult* (2003) – Trimmed L-moments](https://doi.org/10.1016/S0167-9473(02)00250-5)
- [*J.R.M. Hosking* (2007) – Some theory and practical uses of trimmed L-moments](https://doi.org/10.1016/j.jspi.2006.12.002)
- [*R. Serfling & P. Xiao* (2007) – A contribution to multivariate L-moments: L-comoment matrices](https://doi.org/10.1016/j.jmva.2007.01.008)

[IMG-PYPI]: https://img.shields.io/pypi/v/Lmo
[IMG-PY]: https://img.shields.io/pypi/pyversions/Lmo
[IMG-SPEC0]: https://img.shields.io/badge/SPEC-0-green?labelColor=%23004811&color=%235CA038
[IMG-BSD]: https://img.shields.io/github/license/jorenham/Lmo
[IMG-CI]: https://img.shields.io/github/actions/workflow/status/jorenham/Lmo/ci.yml?branch=master
[IMG-PC]: https://img.shields.io/badge/pre--commit-enabled-orange?logo=pre-commit
[IMG-RUFF]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
[IMG-BPR]: https://img.shields.io/badge/basedpyright-checked-42b983

[PYPI]: https://pypi.org/project/Lmo/
[REPO]: https://github.com/jorenham/Lmo
[DOCS]: https://jorenham.github.io/Lmo/
[BSD]: https://github.com/jorenham/Lmo/blob/master/LICENSE
[CI]: https://github.com/jorenham/Lmo/actions/workflows/ci.yml?query=branch%3Amaster

[PC]: https://github.com/pre-commit/pre-commit
[RUFF]: https://github.com/astral-sh/ruff
[BPR]: https://github.com/detachhead/basedpyright/
[PY]: https://github.com/python/cpython
[NP]: https://github.com/numpy/numpy
[SP]: https://github.com/scipy/scipy
[PD]: https://github.com/pandas-dev/pandas
[SPT]: https://github.com/jorenham/scipy-stubs
[SPEC0]: https://scientific-python.org/specs/spec-0000/

## Foundational Literature

- [*J.R.M. Hosking* (1990) – L-moments: Analysis and Estimation of
Distributions using Linear Combinations of Order Statistics
](https://doi.org/10.1111/j.2517-6161.1990.tb01775.x)
- [*E.A.H. Elamir & A.H. Seheult* (2003) – Trimmed L-moments
](https://doi.org/10.1016/S0167-9473(02)00250-5)
- [*J.R.M. Hosking* (2007) – Some theory and practical uses of trimmed
L-moments](https://doi.org/10.1016/j.jspi.2006.12.002)
- [*R. Serfling & P. Xiao* (2007) – A contribution to multivariate
L-moments: L-comoment matrices](https://doi.org/10.1016/j.jmva.2007.01.008)

<!--overview-end-->
32 changes: 16 additions & 16 deletions docs/examples/lmm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"source": [
"np.set_printoptions(precision=5, suppress=True)\n",
"plt.style.use([\n",
" 'dark_background',\n",
" 'seaborn-v0_8-notebook',\n",
" '../styles/gallery.mplstyle',\n",
" \"dark_background\",\n",
" \"seaborn-v0_8-notebook\",\n",
" \"../styles/gallery.mplstyle\",\n",
"])"
]
},
Expand All @@ -45,7 +45,7 @@
"data = [\n",
" 123, 2250, 543, 178, 67, 5100, 248, 1500, 342, 329,\n",
" 543, 980, 1020, 4502, 3406, 856, 297,\n",
"]"
"] # fmt: skip"
]
},
{
Expand Down Expand Up @@ -77,8 +77,8 @@
],
"source": [
"l_stats_data = lmo.l_stats(data)\n",
"print('L-moment statistics [L-loc, L-scale, L-skew, L-kurt]:\\n')\n",
"print('Data:', l_stats_data)"
"print(\"L-moment statistics [L-loc, L-scale, L-skew, L-kurt]:\\n\")\n",
"print(\"Data:\", l_stats_data)"
]
},
{
Expand Down Expand Up @@ -141,12 +141,12 @@
"\n",
"# MM (method of moments) fails, as the variance is non-finite\n",
"# params_mm = GEV.fit(data, method='MM')\n",
"params_mle = GEV.fit(data, method='MLE')\n",
"params_mle = GEV.fit(data, method=\"MLE\")\n",
"params_lmm = GEV.l_fit(data)\n",
"\n",
"print('Fitted GEV parameters [shape (c), loc, scale]:\\n')\n",
"print('MLE:', np.round(params_mle, 5))\n",
"print('L-MM:', np.round(params_lmm, 5))"
"print(\"Fitted GEV parameters [shape (c), loc, scale]:\\n\")\n",
"print(\"MLE:\", np.round(params_mle, 5))\n",
"print(\"L-MM:\", np.round(params_lmm, 5))"
]
},
{
Expand All @@ -170,10 +170,10 @@
"X_mle = GEV(*params_mle)\n",
"X_lmm = GEV(*params_lmm)\n",
"\n",
"print('Fitted GEV L-moment statistics (loc, scale, skew, kurtosis):\\n')\n",
"print('Data:', l_stats_data)\n",
"print('MLE: ', X_mle.l_stats())\n",
"print('L-MM:', X_lmm.l_stats())"
"print(\"Fitted GEV L-moment statistics (loc, scale, skew, kurtosis):\\n\")\n",
"print(\"Data:\", l_stats_data)\n",
"print(\"MLE: \", X_mle.l_stats())\n",
"print(\"L-MM:\", X_lmm.l_stats())"
]
},
{
Expand Down Expand Up @@ -208,8 +208,8 @@
"fig, axs = plt.subplots(1, 2, sharey=True, figsize=(10, 4.5))\n",
"probplot(data, dist=X_mle, plot=axs[0], rvalue=True)\n",
"probplot(data, dist=X_lmm, plot=axs[1], rvalue=True)\n",
"axs[0].set_title('MLE')\n",
"axs[1].set_title('L-MM')\n",
"axs[0].set_title(\"MLE\")\n",
"axs[1].set_title(\"L-MM\")\n",
"plt.tight_layout()"
]
}
Expand Down
Loading

0 comments on commit 46a9329

Please sign in to comment.