mhe / pynrrd

Simple pure-python module for reading and writing nrrd files.
https://pynrrd.readthedocs.io/
MIT License
116 stars 51 forks source link

DeprecationWarning in nrrd/writer.py with numpy 1.19.0 #110

Closed fvdnabee closed 3 years ago

fvdnabee commented 4 years ago

Since numpy 1.19.0 numpy.ndarray.tostring has been deprecated, as per the numpy documentation.

nrrd/writer.py currently issues a warning with the latest numpy version:

.../.env/lib/python3.8/site-packages/nrrd/writer.py:323: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
  raw_data = data.tostring(order=index_order

The fix would be to use numpy.ndarray.tobytes instead.

A quick fgrep shows that tostring is used on the following two locations:

❯ fgrep -r -nI tostring nrrd
nrrd/writer.py:294:        raw_data = data.tostring(order=index_order)
nrrd/writer.py:323:        raw_data = data.tostring(order=index_order)