-
Notifications
You must be signed in to change notification settings - Fork 48
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 RuntimeWarning for nan values #367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of changing the data, which could have adverse side-effects, I think it might be better to allow the data to pass through as nans and then capture the warning, especially if it is expected as in this case. So something like:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore",
message="invalid value encountered in remainder",
category=RuntimeWarning)
lon = np.mod(lon, 360.0 * u.deg if nquant else 360.0)
Which uses a context manager to apply a very specific warnings ignore filter just within the with
block.
Codecov Report
@@ Coverage Diff @@
## master #367 +/- ##
==========================================
+ Coverage 86.34% 86.35% +0.01%
==========================================
Files 21 21
Lines 3624 3627 +3
==========================================
+ Hits 3129 3132 +3
Misses 495 495
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just needs a change log entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a change log
gwcs/geometry.py
Outdated
@@ -200,7 +201,13 @@ def evaluate(self, x, y, z): | |||
lon[h == 0] *= 0 | |||
|
|||
if self._wrap_lon_at != 180: | |||
lon = np.mod(lon, 360.0 * u.deg if nquant else 360.0) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is more readable if instead of catching the warning the call is modified as in
lon = np.mod(lon, 360.0 * u.deg if nquant else 360.0, where=np.isfinite(lon), out=lon)
This addresses #366