Fix `linspace` and `where` dropping units when a plain `0` is combined with a quantity #1928
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
mstimberg
Brian treats a plain
0as compatible with any dimensions (fail_for_dimension_mismatch), but the unit-awarelinspaceandwheretook the dimensions of the result from their first argument only.linspace(0, 10ms, 5)andwhere(cond, 0, v_mV)therefore returned unitless arrays holding SI values, whilelinspace(0ms, 10ms, 5)andwhere(cond, v_mV, 0)worked. In practice,G.v = linspace(0, 10mV, N)fails with a confusingDimensionMismatchError, andwhere(cond, 0, v_mV)/mVsilently 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_linspaceandtest_special_case_numpy_functionsare extended (plain0in either position, an array of zeros, and the error case). The previouswheretest comparednp.asarrayvalues 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.pyandtest_neurongroup.pyon runtime targets: no new failures (Python 3.13, numpy 2.5).