Skip to content

Fix/linters#2774

Merged
dyf merged 6 commits into
AllenInstitute:masterfrom
galenlynch:fix/linters
Feb 20, 2026
Merged

Fix/linters#2774
dyf merged 6 commits into
AllenInstitute:masterfrom
galenlynch:fix/linters

Conversation

@galenlynch
Copy link
Copy Markdown
Contributor

Overview:

Fix ~950 lint violations across 269 files using ruff auto-fixes and targeted manual corrections. No formatting or behavioral changes — strictly lint error resolution and linter configuration.

Addresses:

N/A — maintenance/code health improvement.

Type of Fix:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as expected)
  • Documentation Change

Solution:

Apply lint fixes incrementally in order of risk, from fully automated ruff safe fixes to manual corrections requiring judgment (e.g. pandas boolean comparisons). Configure ruff and flake8 to suppress rules that don't apply well to this codebase (E402 import order, E741 ambiguous names, F403/F405 wildcard imports). Set line-length = 120 in both tools for consistency.

Changes:

  • ruff --fix safe auto-fixes (~250 files) — trailing whitespace, unused imports, comparison ordering, etc.
  • E711, E731== Noneis None, lambda assignments → def statements
  • E712== True/False → idiomatic Python; pandas cases use ~series instead of not series to avoid ValueError
  • F841 — remove unused local variables; add # noqa: F841 for tuple unpacking where removal isn't possible
  • E722 — bare except:except Exception: (72 occurrences)
  • E701 — split single-line compound statements onto two lines (29 occurrences)
  • F401 — add __all__ for intentional re-exports; # noqa for conditional imports
  • F507 — fix format string placeholder mismatch
  • .flake8 config — set max-line-length = 120, add extend-ignore for E402, E741, F403, F405, W503
  • pyproject.toml — add [tool.ruff] with line-length = 120 and matching lint ignore list

Validation:

  • ruff check allensdk passes clean
  • pytest — 1931 passed, 186 skipped, 1 pre-existing error (h5py fixture unrelated to this branch)
  • All 30 notebooks from the notebook_runner CI workflow executed successfully

Screenshots:

N/A — no UI changes.

Unit Tests:

Existing test suite passes; no new tests needed (no behavioral changes).

Script to reproduce error and fix:

# Verify lint passes
uv run --python 3.13 ruff check allensdk

# Run tests
uv run --python 3.13 --extra test pytest

Configuration details:

Python 3.13, Fedora 43, ruff 0.11.x

Checklist

  • My code follows
    Allen Institute Contribution Guidelines
  • My code is unit tested and does not decrease test coverage
  • I have performed a self review of my own code
  • My code is well-documented, and the docstrings conform to
    Numpy Standards
  • I have updated the documentation of the repository where
    appropriate
  • The header on my commit includes the issue number
  • My Pull Request has the latest AllenSDK release candidate branch
    rc/x.y.z as its merge target
  • My code passes all AllenSDK tests

Notes:

This PR is strictly lint fixes — no formatting or runtime behavior changes. The merge target is master rather than an rc/ branch since this repo is in maintenance mode with no active release candidates.

The commit history is structured for reviewable progression:

  1. fix: apply safe ruff auto-fixes — zero-risk automated fixes
  2. fix: E711, E731 — none-comparison and lambda assignment
  3. fix: E712 — boolean comparison with idiomatic pandas
  4. fix: F841 — unused variables
  5. fix: E722, E701, F401, F507 — bare except, multi-statement lines, unused imports, and linter configuration

The E712 pandas fixes deserve attention: ruff's auto-fix would change series == False to not series, which crashes at runtime with ValueError: The truth value of a Series is ambiguous. These were manually fixed to ~series.

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

galenlynch and others added 2 commits February 17, 2026 12:58
After deleting variables, some bare expressions were deleted:

Bare expressions deleted (no side effects — entire line removed):

File: brain_observatory/circle_plots.py
Deleted expression: r * np.cos(angle), r * np.sin(angle)
Why: Pure arithmetic
────────────────────────────────────────
File: brain_observatory/ecephys/.../view_blocks.py
Deleted expression: recorded_blocks[0] → pass
Why: Bare index in else clause
────────────────────────────────────────
File: brain_observatory/eye_tracking/.../DLC_Ellipse_Fitting.py
Deleted expression: 1-frac_completed
Why: Pure arithmetic
────────────────────────────────────────
File: internal/brain_observatory/demix_report.py
Deleted expression: np.zeros(mask.shape)
Why: Array allocated and discarded
────────────────────────────────────────
File: internal/brain_observatory/frame_stream.py
Deleted expression: np.prod(self.frame_shape)
Why: Pure computation
────────────────────────────────────────
File: internal/brain_observatory/roi_filter.py
Deleted expression: create_feature_array(...) → pass
Why: Returns value, no mutation
────────────────────────────────────────
File: internal/ephys/plot_qc_figures.py
Deleted expression: cell_features["long_squares"]["sweeps"]
Why: Dict lookup
────────────────────────────────────────
File: internal/ephys/plot_qc_figures3.py
Deleted expression: cell_features["long_squares"]["sweeps"]
Why: Dict lookup
────────────────────────────────────────
File: internal/model/GLM.py
Deleted expression: kbasprs['b']
Why: Dict lookup
────────────────────────────────────────
File: internal/model/biophysical/fit_stage_1.py
Deleted expression: neuronal_model_data['specimen_id']
Why: Dict lookup
────────────────────────────────────────
File: internal/model/biophysical/make_deap_fit_json.py
Deleted expression: os.path.realpath(os.curdir)
Why: Pure path op
────────────────────────────────────────
File: internal/model/biophysical/passive_fitting/preprocess.py
Deleted expression: down_idxs[1] - down_idxs[0]
Why: Pure arithmetic
────────────────────────────────────────
File: internal/model/glif/error_functions.py
Deleted expression: input_data['subthreshold_long_square_voltage_variance'], np.arange(...)*experiment.neuron.dt, [e.data['interpolated_ISI']] (dead code after raise)
Why: Dict lookup, pure computation, unreachable
────────────────────────────────────────
File: internal/model/glif/preprocess_neuron.py
Deleted expression: sweep_index[...][RESTING_POTENTIAL]*1e-3, long_square_config['all'], long_square_config['subthreshold'], np.mean(El_test_list)
Why: Dict lookups, pure computation
────────────────────────────────────────
File: internal/model/glif/spike_cutting.py
Deleted expression: np.var(xdata)
Why: Pure computation
────────────────────────────────────────
File: internal/pipeline_modules/IVSCC/ephys_nwb/qc.py
Deleted expression: sweep_data['response'], sweep_data['sampling_rate']
Why: Dict lookups
────────────────────────────────────────
File: internal/pipeline_modules/run_neuropil_correction.py
Deleted expression: np.array([...]).mean()
Why: Pure computation
────────────────────────────────────────
File: internal/pipeline_modules/run_observatory_container_thumbnails.py
Deleted expression: input_file['output_json']
Why: Dict lookup
────────────────────────────────────────
File: model/glif/glif_neuron_methods.py
Deleted expression: tcs['voltage'][-1]
Why: Dict/index lookup
────────────────────────────────────────
File: brain_observatory/behavior/swdb/summary_figures.py
Deleted expression: int(session.metadata['ophys_frame_rate'])
Why: Pure type conversion

Bare expressions kept (have side effects):

┌────────────────────────────────────────────────────────┬──────────────────────────────────┐
│                       Expression                       │             Why kept             │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ hero_sweep.sweep_feature("adapt"/"latency"/"mean_isi") │ Forces lazy feature caching      │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ swp.sweep_feature("v_baseline")                        │ Same caching pattern             │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ i_vec.as_numpy()                                       │ NEURON vector conversion         │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ subprocess.check_output([...]) (3 calls)               │ Runs external fitting processes  │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ p.map(func, types)                                     │ Multiprocessing execution        │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ description.manifest.get_path(...)                     │ Manifest path resolution         │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ plt.subplot2grid(...)                                  │ Creates subplot in figure layout │
├────────────────────────────────────────────────────────┼──────────────────────────────────┤
│ All allensdk/test/ expressions                         │ Smoke tests exercising APIs      │
└────────────────────────────────────────────────────────┴──────────────────────────────────┘
- E722: Replace 55 bare `except:` with `except Exception:` (32 files)
- E701: Split 29 single-line compound statements onto separate lines
- F401: Add `__all__` to 5 `__init__.py` re-export files, noqa 2 keras
  availability checks
- F507: Fix format string placeholder mismatch in glif_optimizer_neuron
- Configure ruff and flake8 to suppress E402, E741, F403, F405

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dyf dyf merged commit 1bdca3a into AllenInstitute:master Feb 20, 2026
4 of 6 checks passed
@galenlynch galenlynch deleted the fix/linters branch February 20, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants