Skip to content

Commit

Permalink
Merge pull request #2205 from moj-analytical-services/lint_tf_file
Browse files Browse the repository at this point in the history
Fix lint
  • Loading branch information
RobinL authored Jun 12, 2024
2 parents bcf81f2 + 45a731f commit ee88655
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 54 deletions.
45 changes: 17 additions & 28 deletions .github/workflows/autoblack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,30 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Load cached Poetry installation
uses: actions/cache@v2
with:
path: ~/.local # the path depends on the OS
key: poetry-0 # increment to reset cache
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: '1.7.0'
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
- name: Install poetry using pipx
run: |
pipx install poetry
pipx ensurepath
- uses: actions/setup-python@v5
with:
path: .venv
key: venv-lint-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-01
- name: Install linting dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --only linting
python-version: "3.12.1"
cache: "poetry"

- name: Run Black autoformatter
- name: Install dependencies
run: |
source .venv/bin/activate
python3 -m black .
poetry config virtualenvs.in-project true
poetry install --no-interaction --no-root --only linting
- name: Run Black autoformatter
run: poetry run black .

- name: If needed, commit black changes to the pull request
run: |
git config user.name "$(git log -n 1 --pretty=format:%an)"
git config user.email "$(git log -n 1 --pretty=format:%ae)"
# short-circuit if we have no changes, otherwise attempt to commit and push
# should only fail on forks, in which case contributors will need to manually run black, commit, and push
git diff-index --quiet HEAD || (echo "Attempting to commit changes" && git commit -am 'lint with black' && git push -f)
- name: Run black --check .
run: |
source .venv/bin/activate
python3 -m black --check .
- name: Run black --check
run: poetry run black --check .
39 changes: 15 additions & 24 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,26 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Load cached Poetry installation
uses: actions/cache@v2
with:
path: ~/.local # the path depends on the OS
key: poetry-0 # increment to reset cache
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: '1.7.0'
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
- name: Install poetry using pipx
run: |
pipx install poetry
pipx ensurepath
- uses: actions/setup-python@v5
with:
path: .venv
key: venv-lint-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-00
- name: Install linting dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --only linting
python-version: "3.12.1"
cache: "poetry"

- name: Lint Python files with ruff
- name: Install dependencies
run: |
source .venv/bin/activate
ruff --show-source .
poetry config virtualenvs.in-project true
poetry install --no-interaction --no-root --only linting
- name: Lint Python files with ruff
run: poetry run ruff --show-source .
6 changes: 4 additions & 2 deletions splink/term_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def comparison_level_to_tf_chart_data(cl: dict):
def tf_adjustment_chart(
linker: Linker, col, n_most_freq, n_least_freq, vals_to_include, as_dict
):
# Data for chart

c = linker._settings_obj._get_comparison_by_output_column_name(col)
c = c._as_detailed_records

Expand Down Expand Up @@ -237,7 +237,9 @@ def tf_adjustment_chart(
most_freq = True if not n_most_freq else df["most_freq_rank"] < n_most_freq
mask = selected | least_freq | most_freq

vals_not_included = [val for val in vals_to_include if val not in df["value"].values]
vals_not_included = [
val for val in vals_to_include if val not in df["value"].values
]
if vals_not_included:
warnings.warn(
f"Values {vals_not_included} from `vals_to_include` were not found in "
Expand Down

0 comments on commit ee88655

Please sign in to comment.