fix(v1): NaN scalars of any float dtype, non-unique merge dims, dead-code cleanup#854
Merged
Merged
Conversation
…rop dead code Three follow-ups from the #717 review: - §5 user-NaN check on the scalar fast path used `isinstance(other, float)`, which misses `np.float32`/`np.float16` NaN scalars (they don't subclass Python `float`). Such a scalar was silently added/multiplied into the expression instead of raising (v1) / warning (legacy). Add `semantics.is_nan_scalar` (float | np.floating) and use it at all four scalar sites. - `conform_merge_dims` called `Index.get_indexer` on a shared dim with non-unique labels, raising an opaque `InvalidIndexError` — a regression vs. master, which aligned duplicate labels positionally. Guard on `idx.is_unique` so a non-unique differing index is reported as a §8 mismatch: legacy aligns positionally + warns, v1 raises the canonical "Coordinate mismatch" ValueError. - Remove the unused `LEGACY_SEMANTICS_MESSAGE` constant and the stale `EvolvingAPIWarning` filter cells in the piecewise notebooks (obsolete under `semantics="v1"`; the warning was renamed to LinopySemanticsWarning). Adds regression tests for the NaN-scalar dtypes and the duplicate-label merge on both conventions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
FBumann
force-pushed
the
fix/v1-nan-scalar-cleanup
branch
from
July 20, 2026 08:33
b29d84b to
b8d985e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-ups from reviewing #717.
Note
The following was generated by AI (Claude Opus 4.8), from a review of #717.
Three fixes, targeting the
feat/arithmetic-conventionbranch:1. §5 user-NaN check missed non-
float64numpy scalars. The scalar fast paths in_add_constant_*/_apply_constant_op_*guarded withisinstance(other, float).np.float64subclasses Pythonfloat, butnp.float32/np.float16do not — so anp.float32('nan')scalar slipped past the check and was silently added/multiplied into the expression instead of raising (v1) / warning (legacy). Addedsemantics.is_nan_scalar(float | np.floating) and applied it at all four sites.2.
conform_merge_dimscrashed on a non-unique shared dim. The reorder-vs-mismatch detection calledIndex.get_indexer(ref), which raisesInvalidIndexErroron a non-unique index. This is a regression vs.master, where duplicate labels aligned positionally and succeeded. Guarded onidx.is_unique, so a non-unique differing index is reported as a §8 mismatch — legacy aligns positionally + warns (no crash), v1 raises the canonicalCoordinate mismatchValueErrorinstead of the opaque one.3. Dead-code / stale-doc cleanup. Removed the unused
LEGACY_SEMANTICS_MESSAGEconstant (config.py) and the obsoleteEvolvingAPIWarningfilter cells in the two piecewise example notebooks — those cells setsemantics="v1"yet still filtered a warning that was renamed toLinopySemanticsWarningand no longer fires there.Tests: added regression coverage for the NaN-scalar dtypes (
float64/float32/float16× add/sub/mul/div) and the duplicate-label merge on both conventions.Full suite passes under both semantics (7856 passed, 626 skipped);
ruffand pre-commit clean.