Ignore NumPy warnings in compute_meta#5103
Conversation
dask/array/utils.py
Outdated
| return None | ||
| except Exception: | ||
| np.seterr(**np_err) | ||
| return None |
There was a problem hiding this comment.
You might consider using the finally: block here
try:
...
except:
...
finally:
np.seterr(**np_err)The finally block is run regardless of whether or not there was an error.
There was a problem hiding this comment.
Sure, but there's more code after this block and we still want to keep warnings disabled until just before the last return statement.
There was a problem hiding this comment.
Instead of handling this ourselves, we could also just use:
with np.errstate(all="ignore"):
...
which handles setting and resetting for you.
There was a problem hiding this comment.
Thanks for the suggestion @jcrist, it's indeed a much cleaner solution!
Fixed in latest commits.
|
Minor issue, but it looks like the black check failed. @pentschev you may want to add the pre-commit hooks to run black automatically when committing. |
|
The error here happens because the test failing doesn't get a |
|
@pentschev I wasn't able to reproduce the failure locally either, so I restarted the failing Travis build which is now passing ¯_(ツ)_/¯ |
|
Damn, I've been very unlucky lately with non-reproducible behavior. Thanks for triggering the build again @jrbourbeau! |
|
LGTM, merging. |
|
Thanks fro reviews everyone, thanks for merging @jcrist! |
|
I've just noticed that the following generates a warning (using dask version import dask.array as da
import numpy as np
data0 = da.zeros((3, 10, 10), chunks=(3, 2, 2))
data1 = da.map_blocks(lambda x: np.mean(x, axis=0), data0, dtype=data0.dtype, drop_axis=0)Output: Was this supposed to be silenced as well? This is not a problem with version Thanks! Detailsdask==2.3.0 numpy==1.17.0 pkg-resources==0.0.0 toolz==0.10.0 |
Fixes #5098
cc @mrocklin @shoyer