-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Silence some warnings. #2328
Silence some warnings. #2328
Conversation
58218ff
to
5f0e251
Compare
Most of the remaining warnings are: |
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.
Thanks for the PR.
This is great.
Just a few comment regarding to isel_points
and sel_points
xarray/tests/test_dataarray.py
Outdated
@@ -693,7 +693,7 @@ def test_isel_fancy(self): | |||
da.isel(time=(('points',), [1, 2]), x=(('points',), [2, 2]), | |||
y=(('points',), [3, 4])) | |||
np.testing.assert_allclose( | |||
da.isel_points(time=[1], x=[2], y=[4]).values.squeeze(), | |||
da.isel(time=[1], x=[2], y=[4]).values.squeeze(), |
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.
This does not give the same result.
I think we can just ignore the warning by @pytest.mark.filterwarnings
.
xarray/tests/test_dataset.py
Outdated
@@ -1417,7 +1420,7 @@ def test_sel_fancy(self): | |||
assert_identical(actual['b'].drop('y'), idx_y['b']) | |||
|
|||
with pytest.raises(KeyError): | |||
data.sel_points(x=[2.5], y=[2.0], method='pad', tolerance=1e-3) | |||
data.sel(x=[2.5], y=[2.0], method='pad', tolerance=1e-3) |
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.
Here also, we can just ignore the deprecation warning.
@dcherian - take a look here: #2261 (comment). These may be fixed soon. |
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.
thanks!
@@ -2519,6 +2520,7 @@ class PyNioTestAutocloseTrue(PyNioTest): | |||
|
|||
|
|||
@requires_pseudonetcdf | |||
@pytest.mark.filterwarnings('ignore:IOAPI_ISPH is assumed to be 6370000') |
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.
this is really nice! way better than using filterwarnings manually :)
xarray/plot/plot.py
Outdated
@@ -464,7 +461,7 @@ def _rescale_imshow_rgb(darray, vmin, vmax, robust): | |||
# After scaling, downcast to 32-bit float. This substantially reduces | |||
# memory usage after we hand `darray` off to matplotlib. | |||
darray = ((darray.astype('f8') - vmin) / (vmax - vmin)).astype('f4') | |||
return minimum(maximum(darray, 0), 1) | |||
return np.minimum(np.maximum(darray, 0), 1) |
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.
__array_ufunc__
(which enalbes this on was added new in numpy 1.13. For now, we only require numpy 1.12, so let's stick with using xarray.ufuncs
for now.
@jhamman, @fujiisoup, @shoyer Thanks! |
xarray/core/missing.py
Outdated
@@ -176,6 +176,15 @@ def get_clean_interp_index(arr, dim, use_coordinate=True, **kwargs): | |||
# raise if index cannot be cast to a float (e.g. MultiIndex) | |||
try: | |||
index = index.values.astype(np.float64) | |||
if method != 'nearest': |
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.
rescaling is necessary to avoid underflow/overflow RuntimeWarnings with datetime64 (seen in tests). I've made a similar change to interp() below.
xarray/core/missing.py
Outdated
# Let's keep that compatitibility | ||
index = (index - index.min()) | ||
if len(index) > 1: | ||
index /= index.std() |
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.
Standard deviation is probably fine here, but I wonder if it would be better to guarantee that are all values fall within some fixed range [-MAX, MAX], e.g., by using max() instead:
index = index - index.mean()
index /= EPSILON * np.maximum(index.max(), 1)
where EPSILON is some constant, e.g., 1e-8.
xarray/core/missing.py
Outdated
if len(index) > 1: | ||
index /= index.std() | ||
index /= np.max(np.abs(index)) |
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.
This still needs a fix to account for possibly dividing by zero.
Also, I don't think you need abs() here because subtracting by mean() already centers the data.
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.
The abs()
makes sure that it's always within [-1, 1] right? e.g. if index = [-2, 0, 0.9]
and as long as index
is not all zeroes, it should always work? 🤔
Sorry, I feel like I'm missing something.
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.
Yes, this would work fine unless the array is all zeros/constant.
It still might be worth considering that possibility, though at this point I'm pretty sure we are just refining total edge case behavior.
Maybe:
min_value = index.min()
max_value = index.max()
range_ = max_value - min_value
if range_:
midpoint = (min_value + max_value) / 2
index = index - midpoint
index /= range_
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.
The other option is to not really worry about this at all, besides silencing the warning. float64 is about the best we can do as far as precision, and it's a simple fact that you cannot represent every int64 value exactly in float64. In most cases this isn't a problem.
Arguably, this is the most predictable thing to do. I don't think it really helps with precision to rescale values in general, given that float64 can handle very large exponents just fine without any loss of precision.
I guess the only case where this would make a difference is if you really do care about nanosecond level precision and all your dates are within a single year or so. But that does seem a little unusual for xarray.
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.
The people doing lightning research probably don't think that scenario is all that unusual (don't know for sure, I just remember a conversation with a lightning researcher when he complained about matplotlib's lack of support for nanosecond tickers).
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.
The other option is to not really worry about this at all, besides silencing the warning. float64 is about the best we can do as far as precision, and it's a simple fact that you cannot represent every int64 value exactly in float64. In most cases this isn't a problem.
Ya, so the choice is between using filterwarnings
or rescaling to avoid the warning. I have a mild preference for rescaling because it "solves" the problem. @shoyer: your call...
Hopefully, the lightning research people will chime in / send in a PR if this is actually an issue.
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.
Let's just silence the warning here. I don't think rescaling actually fixes anything, and it's less efficient than silencing it.
These were being triggered by casting datetime64[ns] to float32. We now rescale the co-ordinate before interpolating, except for nearest-neighbour interpolation. The rescaling can change the nearest neighbour, and so is avoided in this case to maintain pandas compatibility.
This reverts commit 76f988f.
This reverts commit 9ac15ef.
This reverts commit 1f1ec52.
21c8c47
to
b985127
Compare
xarray/tests/test_dataarray.py
Outdated
@@ -3532,6 +3532,8 @@ def test_rolling_reduce(da, center, min_periods, window, name): | |||
@pytest.mark.parametrize('min_periods', (None, 1, 2, 3)) | |||
@pytest.mark.parametrize('window', (1, 2, 3, 4)) | |||
@pytest.mark.parametrize('name', ('sum', 'max')) | |||
@pytest.mark.filterwarnings('ignore:Using a non-tuple sequence') |
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.
Silences a warning that seems to be thrown by code in bottleneck
xarray/tests/test_dataarray.py::test_rolling_reduce_nonnumeric[sum-1-3-False]
/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/bottleneck/slow/move.py:149: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
nidx1 = n[idx1]
/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/bottleneck/slow/move.py:150: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
nidx1 = nidx1 - n[idx2]
/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/bottleneck/slow/move.py:152: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
idx[idx1] = nidx1 < min_count
/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/bottleneck/slow/move.py:153: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
idx[idx3] = n[idx3] < min_count
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.
Good catch -- can you file a report in bottleneck? I expect this would be easy to fix.
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.
OK. Filed a report upstream pydata/bottleneck#194 and reverted this commit.
This reverts commit b985127.
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.
LGTM. One small comment on dask version stuff but I'm excited to see this go in.
xarray/tests/test_dask.py
Outdated
with dask.set_options(get=dask.get): | ||
|
||
with (dask.config.set(get=dask.get) if hasattr(dask, 'config') | ||
else dask.set_options(get=dask.get)): |
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.
is this just a version check? Generally, I prefer to see a version comparison so we can more obviously clean these things up when older versions are no longer supported.
(Same comment below)
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.
Ya it's basically a version check. I've made it an explicit version check now.
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.
Let’s merge this!
Remove some warnings.