Skip to content

Commit

Permalink
Merge pull request #10 from vertti/ruff
Browse files Browse the repository at this point in the history
Use Ruff
  • Loading branch information
vertti authored Jan 12, 2025
2 parents d0322e2 + 9017468 commit 59ba620
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 44 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ jobs:
run: |
poetry install
- name: Lint with flake8, black, isort and mypy
- name: Lint with Ruff and Mypy
run: |
poetry run isort --check .
poetry run black --check .
poetry run flake8 .
poetry run ruff check --output-format=github .
poetry run ruff format --diff
poetry run mypy .
poetry run pydocstyle daffy/
- name: Test with pytest
run: |
Expand Down
25 changes: 8 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
repos:
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.11.0 # Replace by any tag/version: https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
1 change: 1 addition & 0 deletions daffy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
annotate your functions so that they document themselves and that documentation is kept up-to-date by validating
the input and output on runtime.
"""

__version__ = "0.5.0"

from .decorators import df_in # noqa
Expand Down
19 changes: 10 additions & 9 deletions daffy/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Decorators for DAFFY DataFrame Column Validator."""

import inspect
import logging
from functools import wraps
Expand All @@ -16,13 +17,13 @@ def _check_columns(df: pd.DataFrame, columns: ColumnsDef, strict: bool) -> None:
if isinstance(columns, dict):
for column, dtype in columns.items():
assert column in df.columns, f"Column {column} missing from DataFrame. Got {_describe_pd(df)}"
assert (
df[column].dtype == dtype
), f"Column {column} has wrong dtype. Was {df[column].dtype}, expected {dtype}"
assert df[column].dtype == dtype, (
f"Column {column} has wrong dtype. Was {df[column].dtype}, expected {dtype}"
)
if strict:
assert len(df.columns) == len(
columns
), f"DataFrame contained unexpected column(s): {', '.join(set(df.columns) - set(columns))}"
assert len(df.columns) == len(columns), (
f"DataFrame contained unexpected column(s): {', '.join(set(df.columns) - set(columns))}"
)


def df_out(columns: Optional[ColumnsDef] = None, strict: bool = False) -> Callable:
Expand Down Expand Up @@ -84,9 +85,9 @@ def wrapper_df_in(func: Callable) -> Callable:
@wraps(func)
def wrapper(*args: str, **kwargs: Any) -> Any:
df = _get_parameter(func, name, *args, **kwargs)
assert isinstance(
df, pd.DataFrame
), f"Wrong parameter type. Expected Pandas DataFrame, got {type(df).__name__} instead."
assert isinstance(df, pd.DataFrame), (
f"Wrong parameter type. Expected Pandas DataFrame, got {type(df).__name__} instead."
)
if columns:
_check_columns(df, columns, strict)
return func(*args, **kwargs)
Expand Down
16 changes: 7 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,18 @@ pandas = ">=1.5.1,<3.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
isort = "^5.12.0"
black = "^23.11.0"
flake8 = "^6.1.0"
pre-commit = "^3.5.0"
pre-commit = "^4.0.0"
mypy = "^1.7.1"
pytest-mock = "^3.12.0"
pytest-cov = "^4.1.0"
coverage = {extras = ["toml"], version = "^7.3.2"}
pydocstyle = "^6.3.0"
ruff = "^0.9.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
multi_line_output = 3

[tool.coverage.run]
branch = true
source = ["daffy"]
Expand All @@ -61,5 +55,9 @@ source = ["daffy"]
show_missing = true
fail_under = 95

[tool.black]
[tool.ruff]
line-length = 120
target-version = "py39"

[tool.ruff.lint]
select = ["F", "E", "W", "I", "N"]

0 comments on commit 59ba620

Please sign in to comment.