← Back to Pull requests

Fix `linspace` and `where` dropping units when a plain `0` is combined with a quantity #1928

Closed
unknown closed this pull request without merging on Nov 12, 2026 09:40 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 06:38 UTC
Author

Brian treats a plain 0 as compatible with any dimensions (fail_for_dimension_mismatch), but the unit-aware linspace and where took the dimensions of the result from their first argument only. linspace(0, 10ms, 5) and where(cond, 0, v_mV) therefore returned unitless arrays holding SI values, while linspace(0ms, 10ms, 5) and where(cond, v_mV, 0) worked. In practice, G.v = linspace(0, 10mV, N) fails with a confusing DimensionMismatchError, and where(cond, 0, v_mV)/mV silently has dimensions of 1/volt instead of being dimensionless.

A small helper now takes the dimensions of the second argument when the first one is dimensionless. It is called after the mismatch check, so this can only happen when the first argument is a zero. Behaviour is unchanged in all other cases, and linspace(1, 2*mV) still raises. Related to #872, which is about other numpy functions losing units.

Tests: test_arange_linspace and test_special_case_numpy_functions are extended (plain 0 in either position, an array of zeros, and the error case). The previous where test compared np.asarray values only, which is why this was not caught. Both extended tests fail on master and pass with this change. test_units.py, test_functions.py, test_timedarray.py, test_spikegenerator.py, test_morphology.py and test_neurongroup.py on runtime targets: no new failures (Python 3.13, numpy 2.5).

Diff: 177 lines (+132 / -45) across 2 files Reviewer: mstimberg Review duration: 13141m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 177 lines diff across 2 files
0.35
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.310
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1928"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.4% (MEDIUM) · Higher = larger blast radius
35.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14% · Safe to merge
14%