Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: ndarrays pickled by 1.16 cannot be loaded by 1.15.4 and lower #12869

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions numpy/core/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
'tracemalloc_domain', 'typeinfo', 'unpackbits', 'unravel_index', 'vdot',
'where', 'zeros']

# For backward compatibility, make sure pickle imports these functions from here
_reconstruct.__module__ = 'numpy.core.multiarray'
scalar.__module__ = 'numpy.core.multiarray'


arange.__module__ = 'numpy'
array.__module__ = 'numpy'
Expand Down
18 changes: 18 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,24 @@ def test_field_access_by_title(self):
if HAS_REFCOUNT:
assert_(base <= sys.getrefcount(s))

@pytest.mark.parametrize('val', [
# arrays and scalars
np.ones((10, 10), dtype='int32'),
np.uint64(10),
])
@pytest.mark.parametrize('protocol',
range(2, pickle.HIGHEST_PROTOCOL + 1)
)
def test_pickle_module(self, protocol, val):
# gh-12837
s = pickle.dumps(val, protocol)
assert b'_multiarray_umath' not in s
if protocol == 5 and len(val.shape) > 0:
# unpickling ndarray goes through _frombuffer for protocol 5
assert b'numpy.core.numeric' in s
else:
assert b'numpy.core.multiarray' in s

def test_object_casting_errors(self):
# gh-11993
arr = np.array(['AAAAA', 18465886.0, 18465886.0], dtype=object)
Expand Down