Skip to content

Fix NumPy 2 incompatibilities that broke every API request - #13

Merged
bmcclellan-cu merged 1 commit into
vector-pythonfrom
fix/numpy2-compatibility
Aug 13, 2026
Merged

Fix NumPy 2 incompatibilities that broke every API request#13
bmcclellan-cu merged 1 commit into
vector-pythonfrom
fix/numpy2-compatibility

Conversation

@bmcclellan-cu

Copy link
Copy Markdown

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_python itself hasn't changed since April 2025 — the rebuild was triggered by an unrelated change, and the dependency arrived silently.

The two failures

1. math.erf on array argumentsvector_main.MAIN wraps its scalar inputs as 1-element arrays, and CD_RB_ENGINEERING4 runs on every request, so this broke all object types:

TypeError: only 0-dimensional arrays can be converted to Python scalars
CD_RB_ENGINEERING4.py:37 in CD_RB_ENGINEERING4

Switched the three from math import erf sites to scipy.special.erf, which is array-aware and already a declared dependency (sentman.py already imported from scipy.special).

2. (3, 1) column vectors assigned into scalar slots — this one only affects object type 4, so it survived the erf fix:

ValueError: setting an array element with a sequence
CD_triFile_effective.py:38 in CD_triFile_effective

PLATEaeroCoeffs returns CDXYZtot/Ftot as (3, 1), so indexing yields size-1 arrays. Flattened both with np.ravel. CD_triFile_effective is 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.

ConfigurationResult
Original code + NumPy 2.5.224 failed
This branch + NumPy 2.5.2, Python 3.12 (Lambda runtime)24 passed
This branch + NumPy 1.26.424 passed

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

  • The geometry test builds a synthetic unit cube rather than shipping real satellite geometry, so it covers the object-type-4 path with no data-disclosure question in a public repo.
  • Adds a test extra for pytest. There is no CI in this repo; these tests are worth wiring into one.
  • Not addressed here: CLL_* and schamberg_* still use math.*, but they are only reachable via GSI_model 3/4, which the API never sends, and they operate on scalars.
  • vector_python/test_main.py is 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-python branch tip with all dependencies unpinned, so the next rebuild is another lottery. Once this merges, swxtrec-cdk should pin this commit SHA and bound numpy/scipy/matplotlib — pinning this package alone would not have prevented the outage, since the breaking change was transitive.

🤖 Generated with Claude Code

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
bmcclellan-cu requested a lite review from CopilotAugust 13, 2026 20:04
@bmcclellan-cu

Copy link
Copy Markdown
Author

@greglucas - For your awareness.

@bmcclellan-cu

Copy link
Copy Markdown
Author

@jennyknuth - for your awareness.

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.erf with array-aware scipy.special.erf in the three call sites that receive NumPy arrays.
  • Flattened (3, 1) column-vector outputs from PLATEaeroCoeffs in CD_triFile_effective to ensure scalar assignments work under NumPy 2.
  • Added a regression test suite (plus a test optional 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
FileDescription
vector_python/tests/test_regression.pyAdds regression tests covering all API-reachable object types/models and validates scalar-shaped outputs under NumPy 2.
vector_python/sentman.pySwitches erf to scipy.special.erf to support array inputs.
vector_python/langmuirKmodel_v3.pySwitches erf to scipy.special.erf to support array inputs.
vector_python/CD_RB_ENGINEERING4.pySwitches erf to scipy.special.erf to support array inputs on the per-request path.
vector_python/CD_triFile_effective.pyFlattens (3, 1) vectors to 1D to avoid size-1 array assignment failures in NumPy 2.
pyproject.tomlAdds 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.

@bmcclellan-cu
bmcclellan-cu merged commit c07d4f3 into vector-pythonAug 13, 2026
1 check passed
Sign up for freeto 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.

2 participants

@bmcclellan-cu