Uh oh!
There was an error while loading. Please reload this page.
Fix NumPy 2 incompatibilities that broke every API request - #13
Merged
Conversation
NumPy 2 no longer converts size-1 arrays to Python scalars, which broke the VECTOR API completely once a Lambda image rebuild pulled it in. Two separate failures: * math.erf() raised TypeError when handed the 1-element arrays MAIN() builds from its scalar inputs. CD_RB_ENGINEERING4 runs on every request, so this took out all object types. Switched the three call sites to scipy.special.erf, which is array-aware and already a dependency. * CD_triFile_effective assigned CDXYZtot/Ftot components, which arrive as (3, 1) column vectors, into scalar array elements. This only affected object type 4, so it survived the erf fix and still broke SORCE, CSIM, the CubeSats and custom uploads. Flattened both to 1-D. Adds regression tests over every object type and accommodation model the API can produce, including the geometry-file path, against expected values recorded on NumPy 1.26.4 that match what production returned. The tests fail on both bugs and pass on NumPy 1.26.4 and 2.5.2 alike. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
bmcclellan-cu
commented
Aug 13, 2026
Author
@greglucas - For your awareness. |
bmcclellan-cu
commented
Aug 13, 2026
Author
@jennyknuth - for your awareness. |
There was a problem hiding this comment.
Pull request overview
Fixes VECTOR API runtime failures introduced by NumPy 2’s stricter scalar/array conversion rules by making the affected math and shape-handling code NumPy-2-safe, and adds regression tests to prevent reintroducing the break.
Changes:
- Replaced
math.erfwith array-awarescipy.special.erfin the three call sites that receive NumPy arrays. - Flattened
(3, 1)column-vector outputs fromPLATEaeroCoeffsinCD_triFile_effectiveto ensure scalar assignments work under NumPy 2. - Added a regression test suite (plus a
testoptional dependency) covering all object types and accommodation models, including synthetic geometry (object type 4).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| vector_python/tests/test_regression.py | Adds regression tests covering all API-reachable object types/models and validates scalar-shaped outputs under NumPy 2. |
| vector_python/sentman.py | Switches erf to scipy.special.erf to support array inputs. |
| vector_python/langmuirKmodel_v3.py | Switches erf to scipy.special.erf to support array inputs. |
| vector_python/CD_RB_ENGINEERING4.py | Switches erf to scipy.special.erf to support array inputs on the per-request path. |
| vector_python/CD_triFile_effective.py | Flattens (3, 1) vectors to 1D to avoid size-1 array assignment failures in NumPy 2. |
| pyproject.toml | Adds a test extra for installing pytest. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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.
Summary
The VECTOR API returned a 500 on every request after a Lambda image rebuild pulled in NumPy 2. NumPy 2 no longer converts size-1 arrays to Python scalars, and this package relied on that in two independent places.
vector_pythonitself hasn't changed since April 2025 — the rebuild was triggered by an unrelated change, and the dependency arrived silently.The two failures
1.
math.erfon array arguments —vector_main.MAINwraps its scalar inputs as 1-element arrays, andCD_RB_ENGINEERING4runs on every request, so this broke all object types:Switched the three
from math import erfsites toscipy.special.erf, which is array-aware and already a declared dependency (sentman.pyalready imported fromscipy.special).2.
(3, 1)column vectors assigned into scalar slots — this one only affects object type 4, so it survived the erf fix:PLATEaeroCoeffsreturnsCDXYZtot/Ftotas(3, 1), so indexing yields size-1 arrays. Flattened both withnp.ravel.CD_triFile_effectiveis the only caller, and those two arrays are used solely for the scalar extractions immediately below, so this is contained.This path is SORCE, CSIM, the CubeSats and custom uploads — fixing only the erf calls would have left all of them broken.
Verification
Test matrix over every object type × accommodation model the API can produce. Expected values were recorded from the unmodified code on NumPy 1.26.4 and match what production returned before the break, so they pin the physics rather than re-recording current behaviour.
Against the pre-break baseline, results are bit-identical on NumPy 1.26.4 and differ by at most
6.7e-16(~3 ULP) on NumPy 2 — that residual is NumPy's own internal routines, not this change, as the bit-identical NumPy 1 run shows.Notes
testextra for pytest. There is no CI in this repo; these tests are worth wiring into one.CLL_*andschamberg_*still usemath.*, but they are only reachable viaGSI_model3/4, which the API never sends, and they operate on scalars.vector_python/test_main.pyis a scratch script with a hardcoded path to a former developer's machine and a broken import. Left alone, but it is not a test.Follow-up
The deployed Dockerfile installs this package from the
vector-pythonbranch tip with all dependencies unpinned, so the next rebuild is another lottery. Once this merges,swxtrec-cdkshould pin this commit SHA and boundnumpy/scipy/matplotlib— pinning this package alone would not have prevented the outage, since the breaking change was transitive.🤖 Generated with Claude Code