-
-
Notifications
You must be signed in to change notification settings - Fork 11k
ENH: Improve support for pathlib.Path objects in load functions #11348
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
Changes from all commits
bd3309d
c4e5aa1
2e1bc67
07cc4b6
d2d1571
6e2db10
84a0b77
271f3e3
5ce8d95
05ddb68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2295,11 +2295,35 @@ def test_loadtxt(self): | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the rationale for this line? A comment might be nice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required such that numpy closes the mem-mapped file. Otherwise you will get weird errors on Windows. |
||
|
||
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) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ndarray.tofile()
discards information on endianness and most recent ARM features switchable endianness (bi-endian)I wonder if this is contributing to #12330.
Certainly this test has just started failing stochastically on shippable / ARM for 2.7 / 3.7, so it may not have been stable in the first place given how recently this was merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't the problem -- I'm preparing the patch now in the linked PR, which is related to testing precision and np.empty() as far as I can tell.