-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
WIP: Remove fragile use of __array_interface__
in ctypeslib.as_array
#10970
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ec8f6d
TST: Add tests for numpy.ctypeslib.as_array
tynn 58e40ce
MAINT: Use assert_equal
eric-wieser 4ec8930
MAINT: Pull repeated decorators up to their containing class
eric-wieser 8a8be50
BUG: Remove fragile use of __array_interface__ in ctypeslib.as_array
eric-wieser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
TST: Add tests for numpy.ctypeslib.as_array
- Loading branch information
commit 1ec8f6d93ea150d79cfea6515ffe02f6d78753b2
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
import pytest | ||
|
||
import numpy as np | ||
from numpy.ctypeslib import ndpointer, load_library | ||
from numpy.ctypeslib import ndpointer, load_library, as_array | ||
from numpy.distutils.misc_util import get_shared_lib_extension | ||
from numpy.testing import assert_, assert_raises | ||
from numpy.testing import assert_, assert_array_equal, assert_raises | ||
|
||
try: | ||
cdll = None | ||
|
@@ -113,3 +113,25 @@ def test_cache(self): | |
a1 = ndpointer(dtype=np.float64) | ||
a2 = ndpointer(dtype=np.float64) | ||
assert_(a1 == a2) | ||
|
||
class TestAsArray(object): | ||
@pytest.mark.skipif(not _HAS_CTYPE, | ||
reason="ctypes not available on this python installation") | ||
def test_array(self): | ||
from ctypes import c_int | ||
at = c_int * 2 | ||
a = as_array(at(1, 2)) | ||
assert_(a.shape == (2,)) | ||
assert_array_equal(a, np.array([1, 2])) | ||
a = as_array((at * 3)(at(1, 2), at(3, 4), at(5, 6))) | ||
assert_(a.shape == (3, 2)) | ||
assert_array_equal(a, np.array([[1, 2], [3, 4], [5, 6]])) | ||
|
||
@pytest.mark.skipif(not _HAS_CTYPE, | ||
reason="ctypes not available on this python installation") | ||
def test_pointer(self): | ||
from ctypes import c_int, cast, POINTER | ||
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. See above. 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. Fixed |
||
p = cast((c_int * 10)(*range(10)), POINTER(c_int)) | ||
a = as_array(p, (10,)) | ||
assert_(a.shape == (10,)) | ||
assert_array_equal(a, np.array(range(10))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Blank line after imports is standard.
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.
Fixed