Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DEP: Speed up WarnOnWrite deprecation in buffer interface #13993

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 1 commit into from
Jul 15, 2019

Conversation

seberg
Copy link
Member

@seberg seberg commented Jul 14, 2019

When a buffer interface does not request a writeable buffer,
simply pass a read-only one when the warn on write flag is set.

This is to give an easier way forward with avoiding the deprecation
warnings: Simply do not ask for a writeable buffer.

It will break code that expects writeable buffers but does not
ask for them specifically a bit harder than would be nice.
But since such code probably should ask for it specifically, this
is likely fine (an RC release has to find out).

The main reason for this is, that this way it plays very will with
cython, which requests writeable buffers explicitly and if declared
const is happy about read-only (so that using const is the best
way to avoid the warning and makes code cleaner).

Closes gh-13929, gh-13974

view->readonly = !PyArray_ISWRITEABLE(self);
/*
* If a read-only buffer is requested on a read-write array, we return a
* read-write buffer as per buffer protocol.
Copy link
Member

Choose a reason for hiding this comment

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

So to be clear, the behavior was not actually dubious as previously remarked, but is specified by the buffer protocol?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the dubious part is either: The buffer protocol should be doing it differently, or, the deprecation side of things is dubious (since this deprecation was used before for the diagonal stuff).

Copy link
Member

Choose a reason for hiding this comment

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

Note the incorrect indent. Tabs?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, wow emberassing, I wonder which of my editors has such an insane setup :).

Copy link
Member

@eric-wieser eric-wieser Jul 15, 2019

Choose a reason for hiding this comment

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

Here's the text I was looking for:

Controls the readonly field. If set, the exporter MUST provide a writable buffer or else report failure. Otherwise, the exporter MAY provide either a read-only or writable buffer, but the choice MUST be consistent for all consumers.

Is "the choice MUST be consistent for all consumers." relevant here? I'm struggling to attach meaning to it.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Test looks good, thanks. This looks like a pretty reasonable change to make, thanks for the clearer comments.

@seberg seberg force-pushed the issue-13929-2 branch 2 times, most recently from 3bbcadc to 08befe1 Compare July 14, 2019 18:51
When a buffer interface does not request a writeable buffer,
simply pass a read-only one when the warn on write flag is set.

This is to give an easier way forward with avoiding the deprecation
warnings: Simply do not ask for a writeable buffer.

It will break code that expects writeable buffers but does not
ask for them specifically a bit harder than would be nice.
But since such code probably should ask for it specifically, this
is likely fine (an RC release has to find out).

The main reason for this is, that this way it plays very will with
cython, which requests writeable buffers explicitly and if declared
`const` is happy about read-only (so that using `const` is the best
way to avoid the warning and makes code cleaner).

Closes numpygh-13929, numpygh-13974
@mattip mattip merged commit 562405c into numpy:maintenance/1.17.x Jul 15, 2019
@charris
Copy link
Member

charris commented Jul 15, 2019

@seberg This is merged, so time for the forward port. The release notes should not be part of that.

@bsipocz
Copy link
Member

bsipocz commented Jul 15, 2019

Issues this refers to to be closed are not auto closed on merge. Is that expected?
(also, I haven't followed the details, but the astropy cython coded are still failing when using the ~current numpy dev version, 1.18.0.dev0+2870105).

@charris
Copy link
Member

charris commented Jul 16, 2019

Issues this refers to to be closed are not auto closed on merge.

It was a usage error. Each issue needs to have its own "Closes", they can't be listed with commas.

@bsipocz
Copy link
Member

bsipocz commented Jul 16, 2019

But neither got closed, usually the first one closes. Anyway, the point is that I still see the issue on astropy CI while this was said to fix gh-13929.

@charris
Copy link
Member

charris commented Jul 16, 2019

1.18.0.dev0+2870105

It was merged in the 1.17.x branch and hasn't been forward ported yet. Can you be more specific as to what is failing, I thought you had fixes?

@bsipocz
Copy link
Member

bsipocz commented Jul 16, 2019

Oh, my mistake, I'm sorry, I didn't see that this is against the 1.17.x branch rather than master. I'll double check and report back either way.

@charris
Copy link
Member

charris commented Jul 16, 2019

@bsipocz Great, I'm just now making the 1.17.0rc2 release.

@seberg
Copy link
Member Author

seberg commented Jul 16, 2019

Will forward port it by tomorrow evening for sure.

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.

5 participants