Joblib: DeprecationWarning: tostring() is deprecated

Created on 23 Jun 2020  路  3Comments  路  Source: joblib/joblib

Hello,

The method joblib.numpy_pickle.NumpyArrayWrapper.write_array is using chunk.tostring, which is deprecated and should be replaced by chunk.tobytes:

File "_my_scrambled_path_/python3.7/site-packages/joblib/numpy_pickle.py", line 103, in write_array
    pickler.file_handle.write(chunk.tostring('C'))
DeprecationWarning: tostring() is deprecated. Use tobytes() instead.

Versions: python 3.7.4, joblib 0.15.1, numpy 1.19.0

Most helpful comment

Actually, master is not using tostring anymore since #1056 .
As we are moving away from old python version (numpy1.6 was released 9years ago), I would say it is okay to only support numpy1.9+ (2014) but it should indeed be fixed in the doc.

All 3 comments

ndarray.tostring is deprecated since numpy 1.19 according to this https://numpy.org/devdocs/reference/generated/numpy.ndarray.tostring.html.

ndarray.tobytes was added in numpy 1.9:
https://numpy.org/devdocs/reference/generated/numpy.ndarray.tobytes.html#numpy.ndarray.tobytes

The README says joblib supports numpy 1.6.1 (not sure if completely up-to-date).

Hmmm I guess in order to avoid the warning we could create a shim function i.e. something like this:

try:
    import numpy as np
    if LooseVersion(np.__version__) >= LooseVersion('1.9'):
        def tobytes(arr, *args, **kwargs):    
            return arr.tobytes(*args, **kwargs)
    else:
        def tobytes(arr, *args, **kwargs):
            return arr.tostring(*args, **kwargs)

except ImportError:
    pass

And then use our tobytes function.

Since numpy moves quite slowly the tostring method is not going to be removed for some time, so doing nothing may be an option ... until our minimum numpy version goes to numpy 1.9.

scikit-learn requires numpy >= 1.13.3 so maybe bumping up the minimal numpy version may be another option.

Actually, master is not using tostring anymore since #1056 .
As we are moving away from old python version (numpy1.6 was released 9years ago), I would say it is okay to only support numpy1.9+ (2014) but it should indeed be fixed in the doc.

joblib 0.16.0 was released yesterday. It does not raise a warning when dumping numpy 1.19 arrays. I believe we can close. Let me know if I missed anything.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

twiecki picture twiecki  路  7Comments

mivade picture mivade  路  9Comments

mfeurer picture mfeurer  路  6Comments

isaacgerg picture isaacgerg  路  4Comments

aseyboldt picture aseyboldt  路  3Comments