-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
DOC, MAINT: Enforce np.ndarray arg for np.put and np.place #7000
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 all commits
Commits
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
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from __future__ import division, absolute_import, print_function | ||
|
||
from numpy import put | ||
from numpy.testing import TestCase, assert_raises | ||
|
||
|
||
class TestPut(TestCase): | ||
|
||
def test_bad_array(self): | ||
# We want to raise a TypeError in the | ||
# case that a non-ndarray object is passed | ||
# in since `np.put` modifies in place and | ||
# hence would do nothing to a non-ndarray | ||
v = 5 | ||
indx = [0, 2] | ||
bad_array = [1, 2, 3] | ||
assert_raises(TypeError, put, bad_array, indx, v) |
This file contains hidden or bidirectional Unicode text that may be interpreted o
10000
r 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
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
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
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.
Could we use the same duck-typing solution as above, with the try/except clause?
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.
It feels little more awkward in this case because
_insert
is not anndarray
method. I suppose you could do something like the following:However, it seems like more contrived compared to the others since we're relying on a method that has nothing to do with what is being called.
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.
What error message do you get when
place
is not valid? What sort of duck typing does it currently support, if any?It might be worth updating
_insert
instead.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.
@shoyer : See #7003, which does a complete revamp of
arr_insert
(that is tied to_insert
) and does the type checking. In the case ofnp.place
, this PR should serve as a stopgap measure until #7003 can be 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.
@shoyer : Sorry, I didn't answer the remainder of your question; I only had seen the "It might be worth" part on my phone when I was reading it.
place
doesn't actually do any duck-typing if you pass in a non-ndarray
to it. Rather, it does nothing, which is why I added thatisinstance
check to the code. However, #7003 will embed that check into the C code, which is preferable. However, I wouldn't mind merging theisinstance
check into the codebase FTTB.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.
OK, agreed!