-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: pathlib support for fromfile(), .tofile() and .dump() #12915
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 1 commit
4a94ee4
eea6b8c
3c060d5
703c59c
998daea
0933c15
9a968f3
6c8f7fb
3c618a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
See #8576
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
|
||
from numpy.core.numeric import pickle | ||
|
||
if sys.version_info[:2] >= (3, 4): | ||
import pathlib | ||
if sys.version_info[0] >= 3: | ||
import builtins | ||
else: | ||
|
@@ -4540,6 +4542,23 @@ def test_roundtrip_filename(self): | |
y = np.fromfile(self.filename, dtype=self.dtype) | ||
assert_array_equal(y, self.x.flat) | ||
|
||
def test_roundtrip_pathlib(self): | ||
if sys.version_info[:2] >= (3, 4): | ||
sorenrasmussenai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
p = pathlib.Path(self.filename) | ||
self.x.tofile(p) | ||
y = np.fromfile(p, dtype=self.dtype) | ||
assert_array_equal(y, self.x.flat) | ||
|
||
def test_roundtrip_dump_pathlib(self): | ||
if sys.version_info[:2] >= (3, 4): | ||
p = pathlib.Path(self.filename) | ||
self.x.dump(p) | ||
if sys.version_info[:2] >= (3, 6): | ||
y = np.load(p) | ||
else: | ||
y = np.load(str(p)) | ||
assert_array_equal(y, self.x) | ||
|
||
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.
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. Good catch, #13684. |
||
def test_roundtrip_binary_str(self): | ||
s = self.x.tobytes() | ||
y = np.frombuffer(s, dtype=self.dtype) | ||
|
Uh oh!
There was an error while loading. Please reload this page.