diff options
author | Paul Müller <paulmueller@users.noreply.github.com> | 2018-11-01 18:28:28 +0100 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2018-11-01 19:28:28 +0200 |
commit | cc761fe87b846228c38eb9b1d71d48cc423f53eb (patch) | |
tree | dd74676e8f6e8cf6ab6ff6d633a710682923e8f1 /numpy/lib/tests | |
parent | b4b62775772aa5f67c469777371374d2b7e27d29 (diff) | |
download | numpy-cc761fe87b846228c38eb9b1d71d48cc423f53eb.tar.gz |
ENH: Improve support for pathlib.Path objects in load functions (#11348)
* ENH: Improve support for pathlib.Path objects in more functions
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_io.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 08800ff97..b746937b9 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -2295,11 +2295,35 @@ class TestPathUsage(object): assert_array_equal(x, a) def test_save_load(self): - # Test that pathlib.Path instances can be used with savez. + # Test that pathlib.Path instances can be used with save. + with temppath(suffix='.npy') as path: + path = Path(path) + a = np.array([[1, 2], [3, 4]], int) + np.save(path, a) + data = np.load(path) + assert_array_equal(data, a) + + def test_save_load_memmap(self): + # Test that pathlib.Path instances can be loaded mem-mapped. + with temppath(suffix='.npy') as path: + path = Path(path) + a = np.array([[1, 2], [3, 4]], int) + np.save(path, a) + data = np.load(path, mmap_mode='r') + assert_array_equal(data, a) + # close the mem-mapped file + del data + + def test_save_load_memmap_readwrite(self): + # Test that pathlib.Path instances can be written mem-mapped. with temppath(suffix='.npy') as path: path = Path(path) a = np.array([[1, 2], [3, 4]], int) np.save(path, a) + b = np.load(path, mmap_mode='r+') + a[0][0] = 5 + b[0][0] = 5 + del b # closes the file data = np.load(path) assert_array_equal(data, a) |