Skip to content

Copy DataFrame-derived arrays so SuperLink works under pandas 3 (Copy-on-Write) - #75

Open
stoiver wants to merge 2 commits into
mdbartos:masterfrom
stoiver:fix-pandas3-cow
Open

stoiver wants to merge 2 commits into
mdbartos:masterfrom
stoiver:fix-pandas3-cow

Conversation

@stoiver

@stoiver stoiver commented Sep 18, 2026

Copy link
Copy Markdown

Fixes #74.

Under pandas 3.0, where Copy-on-Write is the default, .values on a Series or DataFrame is a read-only view. Several arrays built that way in SuperLink.__init__ reach numba kernels compiled with eager, writable-only signatures (boolean[:], int64[:]), so construction fails with No matching definition for argument type(s) ... readonly array(bool, 1d, C) (the storage-type masks) and, once past that, readonly array(int64, 1d, C) (_Sf_method_ik, built as Series.astype(np.int64).values rather than .values.astype(...), so never copied).

This copies those arrays with np.array(...) at construction time: the two storage-type masks in nsuperlink.py and superlink.py, _Sf_method_ik, and the geometry/transect/storage index arrays taken with .loc[...].values. The kernels keep their eager signatures. Verified under pandas 3.0.5 and 2.x with a coupled ANUGA/pipedream model (mass balance closes) and a downstream test suite that previously failed on this.

Independent of #73 (numpy 2 np.bool8); both are needed for a current numpy/pandas.

Under pandas 3.0, where Copy-on-Write is the default, the boolean masks
built from `(_storage_type.str.lower() == 'functional').values` are
read-only views. The storage-area/volume kernels are compiled eagerly with
a `boolean[:]` signature, which numba treats as writable-only, so
SuperLink construction fails with "No matching definition ... readonly
array(bool, 1d, C)". Copy the masks with np.array(), which is accepted
under pandas 2 and 3 and keeps the kernels' eager signatures.

Fixes mdbartos#74

(cherry picked from commit e8fd854)
`_Sf_method_ik` was built as `Series.astype(np.int64).values`, so unlike
the `.values.astype(...)` pattern used everywhere else it was never copied;
under pandas 3 (Copy-on-Write) it is a read-only view and numba_b_ik,
compiled with an eager `int64[:]` argument, rejects it during
SuperLink.__init__. Copy it with np.array(). The same treatment for the
geometry/transect/storage index arrays taken with `.loc[...].values` and
for the tabular-storage index arrays, which reach kernels on code paths
the basic examples do not exercise.

Refs mdbartos#74

(cherry picked from commit 8294e6d)

This branch has not been deployed

No deployments
Sign up for free to 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.

SuperLink construction crashes under pandas 3.0 (Copy-on-Write): numba rejects read-only boolean storage mask

1 participant