-
-
Notifications
You must be signed in to change notification settings - Fork 10.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
warnings.filterwarnings
changes the behavior of np.asarray
#14735
Comments
I think this is expected since the |
I guess it is, but still, having a warning implicitly silenced (even if it happens to have been raised like an exception) was a surprise for me. The code above is a reduced version of So I think catching only try:
...
except Warning:
raise
except Exception:
... |
We can discuss that, but what I meant is that I do not understand why the code does not use:
which I believe works as expected. |
I think that's because pint also works without numpy, so there is more going on in @jthielen, do you have an opinion on this? |
@keewis I've been uncomfortable with how pint uses a So, assuming that explicitly defining |
both, I guess. Considering that we can avoid this issue in pint, @seberg, @eric-wieser, how do you want to handle this? |
I am good with making it |
then, because it seems to be the correct way to me: do you think you could change it to |
Sure PRs welcome ;). But I still think you should try and rewrite it. Note that it would be sufficient to return a lambda which gives the warning and returns the result... |
…numpy#14745) * TST: check whether filtered warnings change behaviour in array() Setting warnings from a converted object's `__getattr__` to errors changes the behaviour of `numpy.array`. See numpy#14735. * MAINT: clear errors raised by `PyArray_LookupSpecial*`
Using
warnings.filterwarnings
with a numpy wrapper class changes the behavior ofnp.asarray
(or rathernp.array
).I believe the reason for this is the equivalent of an
except Exception
block (in the C code), since the warning base classWarning
inherits fromException
.Having
__len__
and__getitem__
is not required to reproduce, but they make the difference a bit more obvious.xref hgrecco/pint#892
Reproducing code example:
Numpy/Python version information:
numpy: 1.17.2
python: 3.7.3
The text was updated successfully, but these errors were encountered: