Skip to content
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

BUG: Fix fill violating read-only flag. #22959

Merged
merged 4 commits into from Jan 8, 2023

Conversation

panosz
Copy link
Contributor

@panosz panosz commented Jan 7, 2023

- See numpy#22922
- `PyArray_FillWithScalar` checks if destination is writeable before
  attempting to fill it
- A relevant test is added as a method of `TestRegression`
@panosz
Copy link
Contributor Author

panosz commented Jan 7, 2023

@seberg I guess this does the job, although I am not sure if checking whether the destination is writable should be done inside PyArray_FillWithScalar.

Also, wonder if test_fill_readonly should cover more test cases.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, that is the correct fix, yes. Just some small comments for fixups to make the change a bit prettier.


if (PyArray_FailUnlessWriteable(arr, "assignment destination") < 0) {
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

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

The comment refers to the allocation below, so either put this check above the comment, or move the check after the first block of variable declarations.

# Ticket #22922
with pytest.raises(ValueError):
a = np.zeros(11)
a.setflags(write=False)
Copy link
Member

Choose a reason for hiding this comment

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

Please move this out of the context, best to make the test as specific as possible? Also we usually put gh-22922 (and maybe "issue" rather than ticket, but it doesn't matter). "Ticket #..." sounds like it predates github :).

I would slightly prefer to move the test into test_multiarray.py which has a few fill related tests.

-- The comment in `PyArray_FillWithScalar` is about the code after the
readonly check, so it was moved to the appropriate location.
-- The `test_fill_readonly` was moved to test_multiarray.TestAttributes.
@panosz
Copy link
Contributor Author

panosz commented Jan 8, 2023

@seberg I modified the code as requested (I believe).
As for the test, I was not sure about which class I should move it to, because it seems that its purpose is more general than what the names of the test classes imply. Eventually I decided to move it to TestAttributes, not because it seemed as a particularly good choice, but because all alternatives seemed worse.

@seberg
Copy link
Member

seberg commented Jan 8, 2023

Thanks @panosz those were the changes I was looking for exactly.

@seberg seberg merged commit 5ed87cb into numpy:main Jan 8, 2023
@seberg seberg changed the title Bug: Fix fill violating read-only flag. BUG: Fix fill violating read-only flag. Jan 8, 2023
@seberg seberg added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Jan 8, 2023
charris pushed a commit to charris/numpy that referenced this pull request Jan 8, 2023
PyArray_FillWithScalar checks if destination is writeable before attempting to fill it.  A relevant test is added as a method of TestRegression

Closes numpygh-22922

Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 8, 2023
charris added a commit that referenced this pull request Jan 9, 2023
BUG: Fix fill violating read-only flag. (#22959)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants