diff options
author | keewis <keewis@users.noreply.github.com> | 2019-10-30 06:33:40 +0100 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2019-10-30 07:33:40 +0200 |
commit | 79d23f0bdc6a5e6bcd280cd93f73fabca8e2469f (patch) | |
tree | b2b7aeb7d6ff2785d3d5dd3cd17bde5044a16cdb /numpy/core/tests | |
parent | 6ed9365aadf992087b26ec30214dfec151ac22a1 (diff) | |
download | numpy-79d23f0bdc6a5e6bcd280cd93f73fabca8e2469f.tar.gz |
BUG: clear only attribute errors in get_attr_string.h::maybe_get_attr (#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 #14735.
* MAINT: clear errors raised by `PyArray_LookupSpecial*`
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_issue14735.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/numpy/core/tests/test_issue14735.py b/numpy/core/tests/test_issue14735.py new file mode 100644 index 000000000..6105c8e6a --- /dev/null +++ b/numpy/core/tests/test_issue14735.py @@ -0,0 +1,29 @@ +import pytest +import warnings +import numpy as np + + +class Wrapper: + def __init__(self, array): + self.array = array + + def __len__(self): + return len(self.array) + + def __getitem__(self, item): + return type(self)(self.array[item]) + + def __getattr__(self, name): + if name.startswith("__array_"): + warnings.warn("object got converted", UserWarning, stacklevel=1) + + return getattr(self.array, name) + + def __repr__(self): + return "<Wrapper({self.array})>".format(self=self) + +@pytest.mark.filterwarnings("error") +def test_getattr_warning(): + array = Wrapper(np.arange(10)) + with pytest.raises(UserWarning, match="object got converted"): + np.asarray(array) |