Skip to content

Commit

Permalink
Merge pull request #215 from lesteve/remove-numpy-less-than-1.3-support
Browse files Browse the repository at this point in the history
[MRG] Remove code specific to numpy < 1.3
  • Loading branch information
ogrisel committed May 7, 2015
2 parents 5b56e90 + 1d51c3b commit ea60fd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions joblib/numpy_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ def read(self, unpickler):
# use getattr instead of self.allow_mmap to ensure backward compat
# with NDArrayWrapper instances pickled with joblib < 0.9.0
allow_mmap = getattr(self, 'allow_mmap', True)
if np_ver >= [1, 3] and allow_mmap:
array = unpickler.np.load(filename, mmap_mode=unpickler.mmap_mode)
else:
# Numpy does not have mmap_mode before 1.3
array = unpickler.np.load(filename)
memmap_kwargs = ({} if not allow_mmap
else {'mmap_mode': unpickler.mmap_mode})
array = unpickler.np.load(filename, **memmap_kwargs)
# Reconstruct subclasses. This does not work with old
# versions of numpy
if (hasattr(array, '__array_prepare__')
Expand Down
14 changes: 7 additions & 7 deletions joblib/test/test_numpy_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def test_memmap_persistence():
filename = env['filename'] + str(random.randint(0, 1000))
numpy_pickle.dump(a, filename)
b = numpy_pickle.load(filename, mmap_mode='r')
if [int(x) for x in np.__version__.split('.', 2)[:2]] >= [1, 3]:
nose.tools.assert_true(isinstance(b, np.memmap))

nose.tools.assert_true(isinstance(b, np.memmap))


@with_numpy
Expand All @@ -223,12 +223,12 @@ def test_memmap_persistence_mixed_dtypes():
filename = env['filename'] + str(random.randint(0, 1000))
numpy_pickle.dump(construct, filename)
a_clone, b_clone = numpy_pickle.load(filename, mmap_mode='r')
if [int(x) for x in np.__version__.split('.', 2)[:2]] >= [1, 3]:
# the floating point array has been memory mapped
nose.tools.assert_true(isinstance(a_clone, np.memmap))

# the object-dtype array has been loaded in memory
nose.tools.assert_false(isinstance(b_clone, np.memmap))
# the floating point array has been memory mapped
nose.tools.assert_true(isinstance(a_clone, np.memmap))

# the object-dtype array has been loaded in memory
nose.tools.assert_false(isinstance(b_clone, np.memmap))


@with_numpy
Expand Down

0 comments on commit ea60fd9

Please sign in to comment.