frejanordsiek / hdf5storage

Python package to read and write a wide range of Python types to/from HDF5 formatted files. Can read/write data to the HDF5 based Matlab v7.3 MAT files.
BSD 2-Clause "Simplified" License
83 stars 24 forks source link

tostring() is deprecated. Use tobytes() instead. #110

Closed Bengt closed 3 years ago

Bengt commented 3 years ago

When running my tests, I see warnings like these:

.tox/py38/lib/python3.8/site-packages/hdf5storage/utilities.py:530: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    buffer=chunk.tostring())[()]

This hints at decoding and encoding between bytes and strings, which might not be trivial to fix. Since that can be tricky in this project, I will not attempt to fix it myself, I fear.

frejanordsiek commented 3 years ago

That is not a decoding/encoding issue. It has to do with numpy a long time ago only having the tostring method and not the tobytes method. I used tostring back then since it made the package compatible with the current numpy versions at the time as well as ones that were old at the time.

So, in principle, it is a trivial search-replace fix. That has already been done in the main branch. But such a solution cannot be done for the 0.1.x branch since that would be breaking compatibility. The 0.1.x branch cannot drop support for these old versions of numpy just as it can't drop support for python 2.6. So, such a change would be a major version increase rather than a bugfix release.

So, I applied a fix in commit f5ce66e in the 0.1.x branch that uses tobytes on newer numpy versions where it is available and tostring on older versions where it not.

The fixed version has been uploaded to PyPI as version 0.1.17

Bengt commented 3 years ago

Awesome work. Thanks!