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.
@sidneymau ran into a weird edge case in a Jupyter notebook when doing
im.array /= 10
raised an AttributeError (that array doesn't have a setter), but performed the operation nonetheless.This seems to be a bug in either Python or numpy. Numpy overloads the inplace arithmetic operations so
ar /= 10
is allowed and works in place. But Python seems to think thatim.array /= 10
would necessarily require a setter, so it raises an AttributeError. This so far is fine, but then Python calls the numpy__idiv__
operation anyway, so the operation succeeds along with an AttributeError being raised.It was at least confusing for Sid, since a Jupyter session doesn't die when that happens, so the state of the array seemed inconsistent with the error messaging.
Anyway, this PR adds a setter, which lets
im.array = blah
work the same way asim.array[:] = blah
, with the slight exception that we are careful about rounding things to the nearest integer if we are assigning to integer arrays rather than truncating as numpy would want to do. (This is consistent with how GalSim does other arithmetic on integer Images.)Note, this replaces Sid's PR #1276, which I wasn't happy with. This implementation never changes the underlying array object. Just lets things be assigned to it as appropriate.