Skip to content

refactor: add StainReference transform methods (2/4) - #1280

Draft
selmanozleyen wants to merge 3 commits into
feat/experimental-params-typeddictsfrom
feat/stain-reference-methods
Draft

refactor: add StainReference transform methods (2/4)#1280
selmanozleyen wants to merge 3 commits into
feat/experimental-params-typeddictsfrom
feat/stain-reference-methods

Conversation

@selmanozleyen

Copy link
Copy Markdown
Member

todo

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.41935% with 7 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/experimental-params-typeddicts@6dcb8f6). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/squidpy/experimental/im/_stain/_reference.py 63.15% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@                          Coverage Diff                           @@
##             feat/experimental-params-typeddicts    #1280   +/-   ##
======================================================================
  Coverage                                       ?   79.21%           
======================================================================
  Files                                          ?       64           
  Lines                                          ?     9362           
  Branches                                       ?     1527           
======================================================================
  Hits                                           ?     7416           
  Misses                                         ?     1396           
  Partials                                       ?      550           
Files with missing lines Coverage Δ
...c/squidpy/experimental/im/_stain/_decomposition.py 97.84% <100.00%> (ø)
src/squidpy/experimental/im/_stain/_normalize.py 93.44% <100.00%> (ø)
src/squidpy/experimental/im/_stain/_reinhard.py 100.00% <100.00%> (ø)
src/squidpy/experimental/im/_stain/_reference.py 84.93% <63.15%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@selmanozleyen
selmanozleyen force-pushed the feat/stain-reference-methods branch 4 times, most recently from 1aa949f to cc0c9ef Compare August 30, 2026 19:02
selmanozleyen added a commit to selmanozleyen/squidpy that referenced this pull request Aug 30, 2026
Brings in scverse#1279 (params as TypedDicts with their defaults declared on the key), scverse#1280
(StainFit and its methods), the enum-to-Literal pass, and the API page restructuring, so
the align work sits on the shape those settle rather than carrying its own copy of it.

Conflicts resolved toward the stack for everything it owns: the params, the defaults
machinery, the enum conversion and the docs templates all come from there, and the three
copies this branch had made of them are dropped.

The alignment surface is what this branch adds on top -- the `stalign_align_*` entry
points, the fit classes they return, and `rasterize_points`/`sample_volume`.

`Stalign*Params` move into `squidpy.types` with the rest. Re-exporting them from
`_align._stalign` deadlocked at import: `types` would have imported the implementation
package whose `__init__` imports `types`. They are declared there now, like every other
params class, and `_stalign` reads them back.

`_matches` in the params test grew a tolerant union arm. It walks a key's declared type to
check the default against it, and `npt.ArrayLike` unions in protocols that are not
`runtime_checkable`, so `isinstance` raised before reaching the `None` arm that actually
matched.
@selmanozleyen
selmanozleyen force-pushed the feat/stain-reference-methods branch from 44f757b to 2827fc0 Compare August 30, 2026 19:46
@selmanozleyen
selmanozleyen force-pushed the feat/stain-reference-methods branch 3 times, most recently from 4aa0278 to a60e049 Compare August 30, 2026 22:09
Public classes in `experimental` declare their kind in the suffix: `*Fit` is an output
carrying the operations that apply it, `*Params` is inert input the caller fills in. With
`transform` and `decompose` on it, this is a fit by that definition -- and it was the only
output class left without the marker, so the index read as if it were a third kind of thing.

Deliberately not renamed before this commit: without behaviour it was arguably just a
parameter bundle, and the methods are what make `*Fit` honest.

`fit_stain_reference() -> StainFit` leaves the verb naming the operation and the noun naming
what comes back. The function keeps its name: it fits a stain *reference*, which is what the
object is; the suffix says what kind of thing it is, not what it models.

No deprecation alias: the module is experimental and says so.
`eq=False` and the explicit `__eq__`/`__hash__` went out with the commit that added the
methods, which left `==` and `hash()` raising on a class that shipped in v1.8.3:

    a == b            ValueError: truth value of an array ... is ambiguous
    hash(a)           TypeError: unhashable type: 'numpy.ndarray'
    a in [b]          ValueError

The dataclass-generated `__eq__` compares field tuples, and comparing array fields is what
raises. `a == a` still answers True by identity short-circuit, so a smoke test passes while
`fit in cohort_fits` blows up on the first non-identical element.

The test that replaced the old one asserted the raising as intended, on the grounds that the
deleted code "silently answered by identity". It did not: it compared `method` plus
element-wise arrays, and the test it replaced asserted exactly that two distinct fits with
equal arrays compare equal. Identity was only ever the *hash*, deliberately, because array
fields cannot produce a value-based one.
@selmanozleyen
selmanozleyen force-pushed the feat/stain-reference-methods branch from a60e049 to 1ba759b Compare August 30, 2026 22:27
@selmanozleyen selmanozleyen changed the title refactor: add StainReference transform methods refactor: add StainReference transform methods (2/4) Sep 3, 2026
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.

1 participant