Skip to content

Commit

Permalink
Update hooks, cosmetics, current pytest-cookies (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmgaudecker committed Sep 15, 2023
1 parent fabfb0f commit 5569b1f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ ___*
!.readthedocs.yml
hooks.egg-info
coverage.xml
tmp*
pytest-of-hmg
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ exclude: ^(\.|{{cookiecutter\.project_slug}})/.+
repos:
- repo: meta
hooks:
# - id: check-hooks-apply # Leave nbqa in here.
- id: check-useless-excludes
# - id: check-hooks-apply # Leave nbqa in here.
# - id: identity # Prints all files passed to pre-commits. Debugging.
- repo: https://github.com/lyz-code/yamlfix
rev: 1.9.0
rev: 1.13.0
hooks:
- id: yamlfix
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -36,20 +36,20 @@ repos:
- id: check-ast
- id: check-docstring-first
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.30.0
rev: v1.32.0
hooks:
- id: yamllint
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.9.1
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.16.0
hooks:
- id: blacken-docs
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
rev: v1.7.5
hooks:
- id: docformatter
args:
Expand All @@ -60,7 +60,7 @@ repos:
- '88'
- --blank
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.259
rev: v0.0.289
hooks:
- id: ruff
# args:
Expand All @@ -73,26 +73,26 @@ repos:
- --extra-keys
- metadata.kernelspec metadata.language_info.version metadata.vscode
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.4
rev: 1.7.0
hooks:
- id: nbqa-black
- id: nbqa-ruff
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-gfm, mdformat-black]
args: [--wrap, '88']
files: (README\.md)
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-myst, mdformat-black]
args: [--wrap, '88']
files: (docs/.)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.5
hooks:
- id: codespell
args: [--skip="**.ipynb"]
Expand Down
5 changes: 2 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- pydata-sphinx-theme>=0.3.0
- pytask>=0.2
- pytest
- pytest-cookies
- pytest-cov
- python
- setuptools_scm
Expand All @@ -30,6 +31,4 @@ dependencies:
- sphinx-panels
- sphinxcontrib-bibtex
- toml
- pip:
- kaleido
- git+https://github.com/andriihomiak/pytest-cookies.git@fix/quotes_in_user_config
- pip: [kaleido]
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ target-version = "py311"
select = ["ALL"]
fix = true
extend-ignore = [
"PLR0133" # Constants being compared, always happening with cookiecutter.
]
"PLR0133", # Constants being compared, always happening with cookiecutter.
"S603", # `subprocess` call: check for execution of untrusted input
"S607", # Starting a process with a partial executable path
]
exclude = [
"docs/scripts"
]
Expand Down
23 changes: 13 additions & 10 deletions {{cookiecutter.project_slug}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
# - id: check-hooks-apply # Leave nbqa in here.
# - id: identity # Prints all files passed to pre-commits. Debugging.
- repo: https://github.com/lyz-code/yamlfix
rev: 1.9.0
rev: 1.13.0
hooks:
- id: yamlfix
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -33,20 +33,20 @@ repos:
- id: check-ast
- id: check-docstring-first{% if cookiecutter.add_linters == 'yes' %}
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.30.0
rev: v1.32.0
hooks:
- id: yamllint{% endif %}
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.9.1
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.16.0
hooks:
- id: blacken-docs
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
rev: v1.7.5
hooks:
- id: docformatter
args:
Expand All @@ -57,7 +57,7 @@ repos:
- '88'
- --blank
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.259
rev: v0.0.289
hooks:
- id: ruff
# args:
Expand All @@ -70,26 +70,29 @@ repos:
- --extra-keys
- metadata.kernelspec metadata.language_info.version metadata.vscode
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.4
rev: 1.7.0
hooks:
- id: nbqa-black
additional_dependencies: [black==23.9.1]
- id: nbqa-ruff
additional_dependencies: [ruff==v0.0.289]
args: ['--ignore=B018,T201']
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-gfm, mdformat-black]
args: [--wrap, '88']
files: (README\.md)
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-myst, mdformat-black]
args: [--wrap, '88']
files: (docs/.)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.5
hooks:
- id: codespell
args: [--skip="**.ipynb"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ def predict_prob_by_age(data, model, group):
_new_data[group] = group_value
predicted[group_value] = model.predict(_new_data)

predicted = pd.DataFrame(predicted)
return predicted
return pd.DataFrame(predicted)
6 changes: 3 additions & 3 deletions {{cookiecutter.project_slug}}/tests/analysis/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

@pytest.fixture()
def data():
np.random.seed(0)
x = np.random.normal(size=100_000)
np.random.default_rng(seed=0)
x = np.random.Generator.normal(size=100_000)
coef = 2.0
prob = 1 / (1 + np.exp(-coef * x))
return pd.DataFrame(
{"outcome_numerical": np.random.binomial(1, prob), "covariate": x},
{"outcome_numerical": np.random.Generator.binomial(1, prob), "covariate": x},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_clean_data_dropna(data, data_info):
def test_clean_data_categorical_columns(data, data_info):
data_clean = clean_data(data, data_info)
for cat_col in data_info["categorical_columns"]:
cat_col = data_info["column_rename_mapping"].get(cat_col, cat_col)
assert data_clean[cat_col].dtype == "category"
renamed_col = data_info["column_rename_mapping"].get(cat_col, cat_col)
assert data_clean[renamed_col].dtype == "category"


def test_clean_data_column_rename(data, data_info):
Expand Down

0 comments on commit 5569b1f

Please sign in to comment.