-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: FutureWarning for void.item(): Will return bytes #10044
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
Conversation
9451ff9
to
4821ab8
Compare
4821ab8
to
40e599a
Compare
I don't like the idea of an unconditional warning, especially when numpy has a habit of calling |
While it would be ideal to make it configurable, it also seems tricky, and the cost/benefit ratio of coding it up seems high. Some points in favor of an unconditional warning:
|
Running |
I'm not sure it's a bug, but I'd also add that it raises an error like in my case 3. (In fact, it gives different errors in Python3 and Python2). It might not be a bug because once we switch to returning |
if (DEPRECATE_FUTUREWARNING( | ||
"the `.item()` method of unstructured void types will return " | ||
"an immutable `bytes` object in the near future instead of the " | ||
"mutable memoryview or integer array returned in numpy 1.13.") |
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.
Maybe worth noting that this is already possible with bytes(void_obj)
and/or bytearray(void_obj)
40e599a
to
c4c3e79
Compare
Let's go with the |
numpy/core/tests/test_regression.py
Outdated
@@ -2233,7 +2233,15 @@ def test_scalar_copy(self): | |||
item = sctype(values.get(sctype, 1)) | |||
item2 = copy.copy(item) | |||
assert_equal(item, item2) | |||
|
|||
def test_void_item_memview(self): |
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.
Missing newline
} | ||
/* | ||
* In the future all the code below will be replaced by | ||
* // For unstructured void types like V4, return a bytes object (copy). |
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.
No C++ comments.
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.
Technically this is not a C++ comment :) I'll fix it though.
@@ -730,6 +732,24 @@ VOID_getitem(void *input, void *vap) | |||
return (PyObject *)ret; | |||
} | |||
|
|||
if (!future_warning_emitted){ |
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.
Hmm, Is this restriction needed? For that matter, is it wanted? What if someone wants to find all the places that need fixing?
Yeah I think I should remove the As to the question of how to turn off the warning if it is not needed, I think the user should just use |
c4c3e79
to
1f78eab
Compare
Merged, thanks Allan. We'll see how it goes ... |
This PR holds off on the changes of #8157 (to fix #8129), and instead issues a FutureWarning if anyone calls
void.item()
. We would push off #8157 to 1.15.