Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@pierreglaser
Copy link
Contributor

@pierreglaser pierreglaser commented Oct 5, 2018

np.ndarray.dumps and np.ndarray.dump will now let the user specify a pickle protocol.

pickling tests now loop over all possible protocols.

Part of #12011, that implements pickle protocol 5 for numpy arrays (this PR is currently being broken out in multiple shorter PRs for simplification and clarity purposes).

pinging @ogrisel @mattip

None
protocol : int, optional
The pickle protocol used to serialize the array.
The default is 2 (in order to maintain python 2 support).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need to use the .. versionadded:: 1.16.0 directive:

    protocol : int, optional
        The pickle protocol used to serialize the array.
        The default is 2 (in order to maintain python 2 support).

         .. versionadded:: 1.16.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

A string naming the dump file.
protocol : int, optional
The pickle protocol used to serialize the array.
The default is 2 (in order to maintain python 2 support).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versionadded

@eric-wieser
Copy link
Member

In my opinion we should deprecate these methods - we already did for np.loads and np.ma.dumps.

@ogrisel
Copy link
Contributor

ogrisel commented Oct 5, 2018

Indeed I find them redundant too.

We would need to rewrite the test to use pickle.loads and pickle.dumps directly then.

@pierreglaser
Copy link
Contributor Author

Should I remove these arguments? Or do we still want to keep the functionality? I will update the tests anyway then.

@ogrisel
Copy link
Contributor

ogrisel commented Oct 5, 2018

No need to add arguments to deprecated methods IMHO.

@pierreglaser pierreglaser changed the title ENH Add protocol as a kwarg to array_dump MNT Update pickling test by making them loop over all protocols Oct 5, 2018
@ogrisel
Copy link
Contributor

ogrisel commented Oct 7, 2018

@eric-wieser do you want this PR to officially deprecate array.dump(s) or just changing the tests so that they are not used by default is enough?

If former is chosen: according to doc/neps/nep-0023-backwards-compatibility.rst, the dump and dumps function should have their docstring updated and issue a DeprecationWarning stating that they are deprecated in 1.16 and will be removed in 1.18 and that the user should use pickle.dump or pickle.dumps directly instead.

There should be a test that checks that the warning is raised but that the methods still work (return the same results as pickle.dump(s).

Finally the changelog should also be updated to mention the deprecation.

@charris charris changed the title MNT Update pickling test by making them loop over all protocols TST, MAINT: Update pickling tests by making them loop over all protocols Oct 8, 2018
@charris
Copy link
Member

charris commented Oct 8, 2018

do you want this PR to officially deprecate array.dump(s)

No, if that happens it should be a separate PR.

Finally the changelog should also be updated to mention the deprecation.

The change logs are generated by a script, but the release notes should have an entry.

@charris
Copy link
Member

charris commented Oct 8, 2018

I note that the code in pickle5 has declarations after statements, which is C99.

@charris charris merged commit 1681fda into numpy:master Oct 8, 2018
@charris
Copy link
Member

charris commented Oct 8, 2018

Thanks @pierreglaser .

pierreglaser added a commit to pierreglaser/numpy that referenced this pull request Oct 10, 2018
All imports of pickle from numpy modules are now done this way:
>>> from numpy.core.numeric import pickle

Also, some loops on protocol numbers are added over pickle tests that
were not caught from numpy#12090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants