Skip to content

Replace deprecated numpy tostring/fromstring with tobytes/frombuffer#379

Open
marouenbg wants to merge 2 commits intonetZoo:develfrom
marouenbg:fix/replace-tostring-fromstring
Open

Replace deprecated numpy tostring/fromstring with tobytes/frombuffer#379
marouenbg wants to merge 2 commits intonetZoo:develfrom
marouenbg:fix/replace-tostring-fromstring

Conversation

@marouenbg
Copy link
Contributor

Summary

Replace all np.ndarray.tostring() / np.fromstring() calls with np.ndarray.tobytes() / np.frombuffer() in lioness.py.

Motivation

np.ndarray.tostring() was deprecated in favor of tobytes() (identical behavior) and was fully removed in numpy 2.3+. This causes AttributeError when running LIONESS with modern numpy versions.

Fixes #378

Changes

  • netZooPy/lioness/lioness.py: replaced 4 active usages and 2 commented-out usages of tostring()/fromstring() with tobytes()/frombuffer().

np.ndarray.tostring() was removed in numpy 2.3+. Replace all
tostring()/fromstring() calls with tobytes()/frombuffer() which have
identical behavior and are the supported API.

Fixes netZoo#378
- test_cobra: use numpy array for mean computation instead of pandas
  Series integer access (KeyError: 0 with string column index)
- condor: use .iloc for positional access on iterrows() Series
  (KeyError: 2 with string column labels)
- condor: use ki.sum() instead of float(sum(ki)) to avoid TypeError
  with np.matrix column vectors in newer numpy
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.

1 participant