Skip to content

Commit

Permalink
replaces black/flake8 formatting/linting with ruff and ensures numpy …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
remrama authored Dec 8, 2024
1 parent 9afdc25 commit ed957c6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/black.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Ruff
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Linting"
uses: astral-sh/ruff-action@v1
- name: "Formatting"
uses: astral-sh/ruff-action@v1
with:
args: "format --check"
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Code guidelines

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

* 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:
* 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:

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

Expand Down
32 changes: 13 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,19 @@ source = ["src"]
show_missing = true
# sort = "Cover"

[tool.black]
[tool.ruff]
line-length = 100
target-version = ['py311']
include = '\.pyi?$'

[tool.flake8]
# W605 : bug when math equation in numpydoc
# W503, W504 : line-break with math operator
# E203: E203 whitespace before ':', not compatible with Black
# DXXX: Docstring related
max-line-length = 100
ignore = ["N806", "N803", "W503", "W504", "W605", "D100", "D200", "D205", "D301", "D400", "D401", "E203"]
target-version = "py311"
exclude = [
".git",
"__pycache__",
"docs",
"build",
"__init__.py",
"examples",
"setup.py",
"__init__.py", # Skip init files bc they use star imports (breaking rules F403, F405)
"notebooks", # Skip jupyter notebook examples
]

[tool.ruff.lint]
select = [
"E4", # Subset of pycodestyle rules
"E7", # Subset of pycodestyle rules
"E9", # Subset of pycodestyle rules
"F", # All Pyflakes rules
"NPY201",
]
statistics = true
2 changes: 1 addition & 1 deletion src/pingouin/bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def _format_bf(bf, precision=3, trim="0"):
"""Format BF10 to floating point or scientific notation."""
if type(bf) == str:
if isinstance(bf, str):
return bf
if bf >= 1e4 or bf <= 1e-4:
out = np.format_float_scientific(bf, precision=precision, trim=trim)
Expand Down
3 changes: 1 addition & 2 deletions src/pingouin/contingency.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ def convert_elem(elem):
elif lower in ("y", "yes", "present", "true", "t", "positive", "p"):
return 1
raise ValueError(
"Invalid value to build a 2x2 contingency "
"table on column {}: {}".format(column, elem)
"Invalid value to build a 2x2 contingency table on column {}: {}".format(column, elem)
)

return series.apply(convert_elem)
Expand Down
1 change: 0 additions & 1 deletion src/pingouin/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pandas as pd
import os.path as op
from pingouin.utils import print_table

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

0 comments on commit ed957c6

Please sign in to comment.