Skip to content

DEP: FutureWarning for void.item(): Will return bytes - #10044

Merged
charris merged 1 commit into
numpy:masterfrom
ahaldane:futurewarn_voiditem
Nov 26, 2017
Merged

charris merged 1 commit into
numpy:masterfrom
ahaldane:futurewarn_voiditem

Conversation

@ahaldane

Copy link
Copy Markdown
Member

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.

@ahaldane
ahaldane force-pushed the futurewarn_voiditem branch from 9451ff9 to 4821ab8 Compare November 17, 2017 17:48
@ahaldane ahaldane added this to the 1.14.0 release milestone Nov 17, 2017
@ahaldane
ahaldane force-pushed the futurewarn_voiditem branch from 4821ab8 to 40e599a Compare November 17, 2017 17:51
@ahaldane ahaldane changed the title MAINT: FutureWarning for void.item(): Will return bytes DEP: FutureWarning for void.item(): Will return bytes Nov 17, 2017
@eric-wieser

Copy link
Copy Markdown
Member

I don't like the idea of an unconditional warning, especially when numpy has a habit of calling .item internally.

@ahaldane

ahaldane commented Nov 17, 2017 •

Copy link
Copy Markdown
Member Author

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:

  1. Even internal uses of void.item() are probably bugs which we would want to hear about.
  2. None of the unit test code ever calls void.item(), even internally.
  3. Any casting or other code that tried to do arr.setitem(void.getitem()) already fails since buffers can't be converted to voids.

@eric-wieser

Copy link
Copy Markdown
Member

Running int(np.void(b'10')) results in void.item being called, but maybe that's a bug too.

@ahaldane

ahaldane commented Nov 17, 2017 •

Copy link
Copy Markdown
Member Author

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 bytes it will "work" (eg, int(np.void(b'10').tobytes() gives 10).

Copy link
Copy Markdown
Member

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)

@ahaldane
ahaldane force-pushed the futurewarn_voiditem branch from 40e599a to c4c3e79 Compare November 19, 2017 18:24
@charris

charris commented Nov 22, 2017

Copy link
Copy Markdown
Member

Let's go with the FutureWarning, that will at least get us some feedback.

Comment thread numpy/core/tests/test_regression.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No C++ comments.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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?

@ahaldane

Copy link
Copy Markdown
Member Author

Yeah I think I should remove the filter_waring_emitted as you said.

As to the question of how to turn off the warning if it is not needed, I think the user should just use warnings.filterwarnings - the warnings module already provides a way of silencing it.

@ahaldane
ahaldane force-pushed the futurewarn_voiditem branch from c4c3e79 to 1f78eab Compare November 26, 2017 16:12
@charris

charris commented Nov 26, 2017

Copy link
Copy Markdown
Member

Merged, thanks Allan. We'll see how it goes ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constructing object array from void array leads to use-after-free

3 participants