Skip to content

Commit 798340a

Browse files
aeiwzclaude
andcommitted
fix: use np.array instead of np.asarray to ensure writable array
np.asarray returns a read-only view when the input dtype already matches, causing np.nan_to_num(copy=False) to raise ValueError on numpy 1.25+ with Python 3.11-3.13. np.array always produces a writable copy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e2e92c4 commit 798340a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

metbit/analysis/opls_da.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def __init__(
198198
_dtype = dtype
199199

200200
# Single allocation: extract to numpy with target dtype, replace NaN in-place.
201-
X_arr = X.to_numpy(dtype=_dtype) if isinstance(X, pd.DataFrame) else np.asarray(X, dtype=_dtype)
201+
X_arr = X.to_numpy(dtype=_dtype) if isinstance(X, pd.DataFrame) else np.array(X, dtype=_dtype)
202202
np.nan_to_num(X_arr, copy=False)
203203
X_df = pd.DataFrame(X_arr, columns=resolved_features)
204204

0 commit comments

Comments
 (0)