Skip to content

Refuse parameter rows of another scope than the settings' (#37) - #63

Merged
guijacquemet merged 1 commit into
mainfrom
claude/scope-strict
Nov 3, 2026
Merged

guijacquemet merged 1 commit into
mainfrom
claude/scope-strict

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Owner decision on #37: strict. Parameters.from_columns now refuses a row whose normalization_scope differs from settings.scope, just as it already refuses a different normalization_method.

Fixes #37

Changes

  • parameter_checks.check_scope(scope, expected, scopes) refuses two kinds of scope:
  • fitting._scope is removed and from_columns calls check_scope. This keeps fitting.py at 591 lines; adding the check inline would have taken it to 608.
  • Tests:
    • test_columns_round_trip_exactly reads its patch rows with NormalizationSettings(scope="patch").
    • New: every row × settings scope pair (3 accepted, 6 refused).
    • New: per-time-point and group values read back unchanged.
  • Docs: contract §8 from_columns row and §9.1, AGENTS map.

Evidence

  • ruff check . and ruff format --check . pass.
  • pytest: 610 passed, 2 skipped (csbdeep, which is not installed locally).
  • Mutation check: with the new comparison disabled, 6 tests fail.
  • No other caller in this repo reads columns with settings of another scope.

Consumer impact (CellPatcher, when it repins past v0.3.2)

CellPatcher currently pins v0.3.2, so nothing changes for it until it repins.

cellpatcher/normalization.py::parameters_from_row (origin/main 79adc3a, lines 270-276) builds NormalizationSettings without scope. Against this branch, two CellPatcher tests fail with normalization_scope is 'patch', but the settings use scope 'image':

  • test_read_patch_table.py::test_an_exported_run_reads_back_as_its_patches
  • test_rgb_normalization.py::test_rgb_raw_export_and_lazy_delivery_give_the_eager_arrays

CellPatcher must pass the run's scope:

brick = mbn.NormalizationSettings(
    image_type=settings.get("image_type", "fluorescence"),
    method=settings.get("method", "percentile"),
    percentile=tuple(settings.get("percentile", (1.0, 99.8))),
    scope=settings.get("scope", "image"),
)

I tried this in a scratch copy, not in the CellPatcher repository. Both failures are fixed, but test_normalization.py::test_raw_patches_of_a_removed_scope_still_normalize_on_load then fails. That test's run_config.json holds the removed scope condition, so NormalizationSettings(scope="condition") raises.

Real rows from a condition- or technical_repeat-scope run hold that scope in normalization_scope. Since #62, from_columns refuses them as an unknown scope whatever settings are passed. For those runs, CellPatcher has two options:

  • refuse with its removed-scope message;
  • build Parameters from the pair columns itself, as it already does for the legacy ;-separated rows. Parameters(...) does not check the scope.

Generated by Claude Code

Parameters.from_columns now refuses a normalization_scope that differs
from settings.scope, as it already did for the method: parameters fitted
for one sampling population are never read as another's. The check lives
in parameter_checks.check_scope (keeps fitting.py under 600 lines).

test_columns_round_trip_exactly now reads its patch rows with patch
settings; new tests cover every row/settings scope pair and per-time-point
groups.

Fixes #37

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
@guijacquemet
guijacquemet merged commit 3bca70d into main Nov 3, 2026
8 checks passed
@guijacquemet
guijacquemet deleted the claude/scope-strict branch November 3, 2026 14:51
@guijacquemet
guijacquemet restored the claude/scope-strict branch November 3, 2026 14:54
@guijacquemet
guijacquemet deleted the claude/scope-strict branch November 14, 2026 08:23
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.

[Sad Catapella N3][Scientific integrity] Parameter deserialization does not verify normalization_scope against requested settings

2 participants