Skip to content

Commit ed957c6

Browse files
authored
replaces black/flake8 formatting/linting with ruff and ensures numpy 2.0 compatibility (#446)
* replace black/flake8 config with ruff config in .toml * run ruff linter * run ruff formatter * remove single unused import manually * replace black github action with ruff github action * enforce numpy 2.0 compatibility with ruff * replace black with ruff in docs * remove explicit gh output format (on by default)
1 parent 9afdc25 commit ed957c6

File tree

7 files changed

+30
-35
lines changed

7 files changed

+30
-35
lines changed

.github/workflows/black.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/ruff.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Ruff
2+
on: [push, pull_request]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: "Linting"
9+
uses: astral-sh/ruff-action@v1
10+
- name: "Formatting"
11+
uses: astral-sh/ruff-action@v1
12+
with:
13+
args: "format --check"

docs/contributing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Code guidelines
1212

1313
*Before starting new code*, we highly recommend opening an issue on `GitHub <https://github.com/raphaelvallat/pingouin>`_ to discuss potential changes.
1414

15-
* Please use standard `pep8 <https://pypi.python.org/pypi/pep8>`_ and `flake8 <http://flake8.pycqa.org/>`_ Python style guidelines. Pingouin uses `black <https://github.com/psf/black>`_ for code formatting. Before submitting a PR, please make sure to run the following command in the root folder of Pingouin:
15+
* Please use standard `pep8 <https://pypi.python.org/pypi/pep8>`_ and `flake8 <http://flake8.pycqa.org/>`_ Python style guidelines. Pingouin uses `ruff <https://github.com/astral-sh/ruff>`_ for code formatting. Before submitting a PR, please make sure to run the following command in the root folder of Pingouin:
1616

1717
.. code-block:: bash
1818
19-
$ black . --line-length=100
19+
$ ruff format --line-length=100
2020
2121
* Use `NumPy style <https://numpydoc.readthedocs.io/en/latest/format.html>`_ for docstrings. Follow existing examples for simplest guidance.
2222

pyproject.toml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,19 @@ source = ["src"]
107107
show_missing = true
108108
# sort = "Cover"
109109

110-
[tool.black]
110+
[tool.ruff]
111111
line-length = 100
112-
target-version = ['py311']
113-
include = '\.pyi?$'
114-
115-
[tool.flake8]
116-
# W605 : bug when math equation in numpydoc
117-
# W503, W504 : line-break with math operator
118-
# E203: E203 whitespace before ':', not compatible with Black
119-
# DXXX: Docstring related
120-
max-line-length = 100
121-
ignore = ["N806", "N803", "W503", "W504", "W605", "D100", "D200", "D205", "D301", "D400", "D401", "E203"]
112+
target-version = "py311"
122113
exclude = [
123-
".git",
124-
"__pycache__",
125-
"docs",
126-
"build",
127-
"__init__.py",
128-
"examples",
129-
"setup.py",
114+
"__init__.py", # Skip init files bc they use star imports (breaking rules F403, F405)
115+
"notebooks", # Skip jupyter notebook examples
116+
]
117+
118+
[tool.ruff.lint]
119+
select = [
120+
"E4", # Subset of pycodestyle rules
121+
"E7", # Subset of pycodestyle rules
122+
"E9", # Subset of pycodestyle rules
123+
"F", # All Pyflakes rules
124+
"NPY201",
130125
]
131-
statistics = true

src/pingouin/bayesian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def _format_bf(bf, precision=3, trim="0"):
1212
"""Format BF10 to floating point or scientific notation."""
13-
if type(bf) == str:
13+
if isinstance(bf, str):
1414
return bf
1515
if bf >= 1e4 or bf <= 1e-4:
1616
out = np.format_float_scientific(bf, precision=precision, trim=trim)

src/pingouin/contingency.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ def convert_elem(elem):
367367
elif lower in ("y", "yes", "present", "true", "t", "positive", "p"):
368368
return 1
369369
raise ValueError(
370-
"Invalid value to build a 2x2 contingency "
371-
"table on column {}: {}".format(column, elem)
370+
"Invalid value to build a 2x2 contingency table on column {}: {}".format(column, elem)
372371
)
373372

374373
return series.apply(convert_elem)

src/pingouin/datasets/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pandas as pd
22
import os.path as op
3-
from pingouin.utils import print_table
43

54
ddir = op.dirname(op.realpath(__file__))
65
dts = pd.read_csv(op.join(ddir, "datasets.csv"), sep=",")

0 commit comments

Comments
 (0)