MAINT, TST refactor pickle imports and tests #12133
Conversation
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
|
|
||
|
|
||
| class TestPickling(object): | ||
| def test_highest_available_pickle_protocol(self): |
There was a problem hiding this comment.
This test is a bit strange, why is it needed?
There was a problem hiding this comment.
By the time I started writing this set of PRs, it was a sort of meta-test that made sure all pickle protocol test loops were actually including protocol 5 if possible (e.g if pickle5 was installed), especially for the ndarray class.
Now things have a bit changed: we loop over protocols in plenty of other test files, yet this test is only ran here. I agree that this test is less relevant now, and it can actually be removed for the sake of clarity and consistency.
| f.close() | ||
| assert_array_equal(a, b) | ||
| for proto in range(2, pickle.HIGHEST_PROTOCOL + 1): | ||
| f = BytesIO() |
There was a problem hiding this comment.
I think most of these types of tests should be changed to use BytesIO as a context manager, but that is out of scope for this PR.
|
Thanks @pierreglaser . |
This PR is essentially the first commit of #12011. If you'd rather merge #12011 directly, feel free to close it.
It is a numpy-wide refactor of pickle importing and
pickle.dump(s)function testing. Most notably:pickle.dumpstests that I did not catch in TST, MAINT: Update pickling tests by making them loop over all protocols #12090 that are now looped over for every pickle protocoleach time we import pickle in python, we import it once this way, in
numpy.core.numeric, and then each timepickleis used in other files, we import it fromnumpy.core.numeric. The only time we importpickleanother way is innumpy/core/setup.pyNow,
numpyshould be cleanpickle-wise, meaning:np.ndarray.dump(s)call in the test suite.