Skip to content

Commit

Permalink
check ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Hông-Lan Botterman committed Sep 5, 2024
1 parent ab79496 commit cf35fde
Show file tree
Hide file tree
Showing 57 changed files with 4,169 additions and 2,436 deletions.
9 changes: 0 additions & 9 deletions .flake8

This file was deleted.

23 changes: 13 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name: Publish Package on PYPI
name: Publish Package on PyPI

on:
release:
types: [published]


jobs:
deploy:

runs-on: ubuntu-latest

steps:
Expand All @@ -16,14 +14,19 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
poetry install
- name: Build package
run: python setup.py sdist bdist_wheel
run: |
poetry build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
env:
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish
34 changes: 16 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Unit tests
on:
push:
branches:
-dev
-main
- "**"
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:
Expand All @@ -22,24 +21,23 @@ jobs:
shell: bash -l {0}

steps:
- name: Git clone
- name: Checkout
uses: actions/checkout@v3
- name: Set up venv for ci
uses: conda-incubator/setup-miniconda@v2
- name: Python
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}
environment-file: environment.ci.yml
- name: Lint with flake8
run: |
flake8
- name: Test with pytest
run: |
make coverage
- name: typing with mypy
run: |
mypy qolmat
echo you should uncomment mypy qolmat and delete this line
- name: Upload coverage reports to Codecov
python-version: ${{ matrix.python-version }}
- name: Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
- name: Lock
run: poetry lock --no-update
- name: Install
run: poetry install
- name: Checkers
run: make checkers
- name: Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
47 changes: 17 additions & 30 deletions .github/workflows/test_quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
shell: bash -l {0}

steps:
- name: Git clone
- name: Checkout
uses: actions/checkout@v3

# See caching environments
Expand All @@ -29,40 +29,27 @@ jobs:
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: env_qolmat_ci
use-mamba: true
python-version: ${{ matrix.python-version }}

- name: Get Date
id: get-date
run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT

- name: Cache Conda env
- name: Cache Poetry dependencies
uses: actions/cache@v2
with:
path: ${{ env.CONDA }}/envs
key:
conda-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('environment.ci.yml') }}-${{ env.CACHE_NUMBER
}}
env:
# Increase this value to reset cache if environment.ci.yml has not changed
CACHE_NUMBER: 0
id: cache

- name: Update environment
run: mamba env update -n env_qolmat_ci -f environment.ci.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: Lint with flake8
run: |
flake8
- name: Test with pytest
run: |
make coverage
- name: Test docstrings
run: make doctest
- name: typing with mypy
run: |
mypy qolmat
echo you should uncomment mypy qolmat and delete this line
path: |
~/.cache/pypoetry/cache
~/.cache/pypoetry/artifacts
key: poetry-${{ runner.os }}-cache-${{ steps.get-date.outputs.today }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
poetry-${{ runner.os }}-cache-
- name: Install Poetry
run :
mamba install -c conda-forge poetry -y
poetry install

- name: Checkers
run: make check-coverage check-types
20 changes: 4 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@ repos:
exclude: (docs/)
- id: trailing-whitespace
exclude: (docs/)
- repo: https://github.com/psf/black
rev: 22.8.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: black
args:
- "-l 99"
# Flake8
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
hooks:
- id: mypy
args: [--ignore-missing-imports]
additional_dependencies: [types-requests]
- id: ruff
- id: ruff-format
33 changes: 27 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
coverage:
pytest --cov-branch --cov=qolmat --cov-report=xml tests

doctest:
pytest --doctest-modules --pyargs qolmat
check-coverage:
poetry run pytest --cov-branch --cov=qolmat/ --cov-report=xml tests/

doc:
make html -C docs
check-poetry:
poetry check --lock

check-quality:
poetry run ruff check qolmat/ tests/

check-security:
poetry run bandit --recursive --configfile=pyproject.toml qolmat/

check-tests:
poetry run pytest tests/

check-types:
poetry run mypy qolmat/ tests/

checkers: check-coverage check-types

clean:
rm -rf .mypy_cache .pytest_cache .coverage*
rm -rf **__pycache__
make clean -C docs

coverage:
poetry run pytest --cov-branch --cov=qolmat --cov-report=xml tests

doc:
make html -C docs

doctest:
poetry run pytest --doctest-modules --pyargs qolmat
18 changes: 0 additions & 18 deletions environment.ci.yml

This file was deleted.

9 changes: 4 additions & 5 deletions examples/tutorials/plot_tuto_benchmark_TS.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
=========================
"""=========================
Benchmark for time series
=========================
Expand All @@ -14,18 +13,18 @@
# First import some libraries

import numpy as np
import pandas as pd

np.random.seed(1234)
from matplotlib import pyplot as plt
import matplotlib.ticker as plticker
from matplotlib import pyplot as plt

tab10 = plt.get_cmap("tab10")

from sklearn.linear_model import LinearRegression

from qolmat.benchmark import comparator, missing_patterns
from qolmat.imputations import imputers
from qolmat.utils import data, plot
from sklearn.linear_model import LinearRegression

# %%
# 1. Data
Expand Down
12 changes: 5 additions & 7 deletions examples/tutorials/plot_tuto_categorical.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
==============================
"""==============================
Benchmark for categorical data
==============================
Expand All @@ -8,14 +7,13 @@
It comprehends passengers features as well as if they survived the accident.
"""

from qolmat.imputations import preprocessing, imputers
from sklearn.pipeline import Pipeline

from qolmat.benchmark import comparator, missing_patterns
from qolmat.imputations import imputers, preprocessing
from qolmat.imputations.imputers import ImputerRegressor
from qolmat.benchmark import missing_patterns
from qolmat.benchmark import comparator
from qolmat.utils import data

from sklearn.pipeline import Pipeline

# %%
# 1. Titanic dataset
# ---------------------------------------------------------------
Expand Down
12 changes: 5 additions & 7 deletions examples/tutorials/plot_tuto_diffusion_models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
"""
===============================================
"""===============================================
Tutorial for imputers based on diffusion models
===============================================
In this tutorial, we show how to use :class:`~qolmat.imputations.diffusions.ddpms.TabDDPM`
and :class:`~qolmat.imputations.diffusions.ddpms.TsDDPM` classes.
"""

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from qolmat.utils import data
from qolmat.benchmark import comparator, missing_patterns

from qolmat.imputations.imputers_pytorch import ImputerDiffusion
from qolmat.imputations.diffusions.ddpms import TabDDPM, TsDDPM
from qolmat.imputations.imputers_pytorch import ImputerDiffusion
from qolmat.utils import data

# %%
# 1. Time-series data
Expand Down
9 changes: 4 additions & 5 deletions examples/tutorials/plot_tuto_hole_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
============================================
"""============================================
Tutorial for hole generation in tabular data
============================================
Expand All @@ -17,13 +16,10 @@
"""
from typing import List

from io import BytesIO
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import requests
import zipfile

from qolmat.benchmark import missing_patterns
from qolmat.utils import data
Expand Down Expand Up @@ -90,6 +86,7 @@ def visualise_missing_values(df_init: pd.DataFrame, df_mask: pd.DataFrame):
initial dataframe
df_mask : pd.DataFrame
masked dataframe
"""
df_tot = df_init.copy()
df_tot[df_init.notna()] = 0
Expand Down Expand Up @@ -117,6 +114,7 @@ def get_holes_sizes_column_wise(data: np.ndarray) -> List[List[int]]:
-------
List[List[int]]
List of hole size for each column.
"""
hole_sizes = []
for col in range(data.shape[1]):
Expand Down Expand Up @@ -153,6 +151,7 @@ def plot_cdf(
list of labels
colors : List[str]
list of colors
"""
_, axs = plt.subplots(1, df.shape[1], sharey=True, figsize=(15, 3))

Expand Down
6 changes: 2 additions & 4 deletions examples/tutorials/plot_tuto_mcar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
============================================
"""============================================
Tutorial for Testing the MCAR Case
============================================
Expand All @@ -8,10 +7,9 @@

# %%
# First import some libraries
from matplotlib import pyplot as plt

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from scipy.stats import norm

from qolmat.analysis.holes_characterization import LittleTest
Expand Down
Loading

0 comments on commit cf35fde

Please sign in to comment.