Skip to content

Stack - Upgrade numpy version - #23

Merged
jomey merged 20 commits into
mainfrom
copilot/research-update-python-numpy
Oct 28, 2026
Merged

jomey merged 20 commits into
mainfrom
copilot/research-update-python-numpy

Conversation

@jomey

@jomey jomey commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

This pull request refactors how NumPy arrays are passed between Python and C code.

The main change is to use direct typed-memoryview views into NumPy arrays instead of making copies, ensuring that the C code writes directly into the output arrays. C-contiguous arrays and correct dtype is now enforced at initialization.

Array Handling Improvements:

  • pysnobal/c_snobal/snobal.pyx: Replaced repeated use of np.ascontiguousarray and PyArray_SimpleNewFromData with direct typed-memoryview views for all float64 output arrays. Special handling is retained for arrays that require dtype conversion, such as mask and layer_count. [1] [2]
  • pysnobal/ipysnobal.py: Modified initialization to enforce float64 C-contiguous layout for all arrays in the state dictionary, ensuring compatibility with the new memoryview approach and preventing silent loss of written-back state.

Build and Compatibility Updates:

  • setup.py: Added NPY_NO_DEPRECATED_API macro to suppress warnings about deprecated NumPy C API usage.

Minor Code Cleanup:

AWSM dependency

The corresponding PR to update the test suite is here: iSnobal/awsm#44
Should be re-run after this is merged.

Python version

This now supports Python 3.14, Numpy 2.5, and Pandas 3.1

Copilot AI balanced review requested due to automatic review settings October 12, 2026 19:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Point-model integer arrays are incompatible with the new memoryviews, and the NumPy constraint removal conflicts with repository guidance.

2 open findings
What changed in this PR

Refactors Python/C array exchange to use zero-copy typed memoryviews and broadens NumPy build compatibility.

Changes:

  • Enforces contiguous float64 state arrays.
  • Replaces copied output buffers with direct memoryviews.
  • Removes the NumPy version cap and disables deprecated C APIs.
File Description
setup.py Defines the non-deprecated NumPy C API.
pysnobal/​ipysnobal.py Normalizes initialized state arrays.
pysnobal/​c_snobal/​snobal.pyx Passes output arrays directly to C.
pyproject.toml Removes the NumPy build-version constraint.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pysnobal/c_snobal/snobal.pyx Resolved
Comment thread pyproject.toml Resolved
@jomey jomey changed the title Stack update - Remvoe dependency for ceratin numpy version Stack - Upgrade numpy version Oct 12, 2026
@jomey
jomey requested review from a team and j-amma October 12, 2026 21:11
@jomey jomey added the maintenance Package architecture, config, or library dependency work label Oct 12, 2026
@jomey
jomey force-pushed the copilot/research-update-python-numpy branch 6 times, most recently from 228e6a8 to 7d45812 Compare October 21, 2026 21:50
@jomey
jomey enabled auto-merge October 21, 2026 21:55
@jomey
jomey force-pushed the copilot/research-update-python-numpy branch from ea72b20 to 6e667ee Compare October 21, 2026 22:03
@jomey

jomey commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

To get the tests passing we first must work on an updated conda environment.
This is started here:
iSnobal/model_setup#40

Comment thread .github/workflows/latest_python.yaml Resolved
Comment thread tests/test_input_parsing.py Resolved
Comment thread pysnobal/pysnobal.py Resolved
Copilot AI and others added 9 commits October 28, 2026 12:48
From Copilot:
Use typed memoryviews in do_tstep_grid for NumPy 2.x compatibility

Replace all `cdef np.ndarray[dtype, mode="c", ndim=2]` buffer declarations
with typed memoryviews (`double[:, ::1]` / `int[:, ::1]`) and remove the
`np.PyArray_SimpleNewFromData` / `np.npy_intp` C-API calls.  Write-back of
C results now uses a direct memoryview slice-assignment.
From @copilot:
Defining NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION tells NumPy's headers:
"compile against only the stable post-1.7 API."

This is the same API surface that NumPy 2.x retains — the symbols that were
removed in 2.0 are a strict subset of what was already deprecated before 1.7.

Placing the macro in setup.py's Extension definition means it is applied
uniformly to every .c file compiled in that extension (including the libsnobal
C sources), not just the Cython-generated one.
Also clean up other calls from legacy setup. Remove codecov or tox clean up artifacts.
Update the initializer of a point execution to initialize all arrays as float64
Change one call to calculate timesteps and use a syntax that is friendly with
Pandas up to 3.0
Enables use of the `pip install --group dev` call for dev setups
jomey added 8 commits October 28, 2026 12:48
It is not out yet (and not sure if even planned), but makes for less surprises
of a future maintainer
Remove unused targets and consolidate clean targets. Also update doc strings.
This makes it compatible with version > 3

Warning Message:
'H' is deprecated and will be removed in a future version, please use 'h' instead.
The entire iSnobal stack (AWSM, SMRF, topocalc) was recently upgraded to
support 3.14
@jomey
jomey force-pushed the copilot/research-update-python-numpy branch from 362f1f2 to 7a26894 Compare October 28, 2026 18:48
Comment thread pysnobal/defaults.py Resolved
Comment thread tests/test_pysnobal_real_data.py Resolved
@j-amma

j-amma commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

To get the tests passing we first must work on an updated conda environment. This is started here: iSnobal/model_setup#40

PR Completed: iSnobal/model_setup@e94c1bd

@j-amma j-amma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Much cleaner! Thanks @jomey

@jomey
jomey merged commit d25fb55 into main Oct 28, 2026
6 checks passed
@jomey
jomey deleted the copilot/research-update-python-numpy branch October 28, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Package architecture, config, or library dependency work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants