-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix __eq__
, make arithmetic operations fully consistent with masked arrays, deprecate gu.misc.array_equal
and bug fixes
#313
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__eq__
, make arithmetic operations fully consistent with masked arrays, deprecate gu.misc.array_equal
and bug fixes
Merging this to check if it solves the issue of xDEM, which is apparently not linked to nodata (still fails with -9999), but more likely dtypes during arithmetic operations (changed in this PR), and that I cannot reproduce locally... |
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
adehecq
reviewed
Sep 20, 2022
This was referenced Sep 21, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR modifies the behaviour of
__eq__
to have a rigorous equality check between Raster objects.As a result, a certain number of test failed linked to arithmetic operations, and thus a correction was made to
_overloading_check
anddata.setter
to avoid inconsistencies that were created in the masked arrays. Then, tests relying on__eq__
were updated to be more robust.Additionally, the custom function
gu.misc.array_equal
initially introduced for back-compatibility and for which the behaviour was not clearly defined to all (it only checked valid data, but did not compare unmaskeddata
, themask
themselves, or thedtypes
as some of us expected) is now deprecated as similar functionalities exist in NumPy:np.array_equal(equal_nan=True)
, ornp.ma.allequal
, or in our new__eq__
.Finally, a small reprojection bug was fixed, a couple tests that did not work after the
__eq__
update, and the type linting ofRaster.astype
that was missing a default parameter for one of itsLiteral
.Note: as the
array_equal
function lives in the same module asdeprecate
, I could not use thedeprecate
decorator (could only made it work from another module), so the function is removed entirely. I think this is fine as it is a "developer" function we use exclusively for tests, and not a "user" function.Details
In details, this PR:
__eq__
compute an exact Raster equality, now considering masked values indata.data
, the maskdata.mask
, the fill_valuedata.fill_value
and the dtypedata.dtype
(called by to get the Raster dtype, so always matches);dtype
or an encapsulation bynp.ma.masked_array
in_overloading_check
anddata.setter
to ensure the masked array operations withRaster
always behave exactly like they would for arithmetic operation of masked arrays (the issue Strange behaviour ofarray_interface
on mask and nodata setting #299 was triggered by passing a masked array asdata=
, i.e. first argument, intonp.ma.masked_array
. This happened in bothdata.setter
and_overloading_check
in some cases);__array_ufunc__
(which takes over reverse arithmetic functions when array is passed first) because of exceptions in a few arithmetic functions (found a NumPy inconsistency!),test_georaster.py
andtest_satimg.py
when checking raster or array equality: use__eq__
when relevant instead of array comparison, use doublenp.array_equal
when both raw data and mask should be the same, or usenp.ma.allequal
when valid data should be the same,gu.misc.array_equal
that is now equivalent tonp.ma.allequal
but no needed for backwards compatibility (see Deprecategu.misc.array_equal
fornp.array_equal
and enforce Numpy>1.19 #290).Resolves #312
Resolves #299
Resolves #290