diff --git a/diffsims/tests/crystallography/test_get_hkl.py b/diffsims/tests/crystallography/test_get_hkl.py index 0c447e97..7da4f5d2 100644 --- a/diffsims/tests/crystallography/test_get_hkl.py +++ b/diffsims/tests/crystallography/test_get_hkl.py @@ -33,7 +33,7 @@ class TestGetHKL: @pytest.mark.parametrize("highest_hkl, n", [([1, 2, 3], 105), ([1, 1, 1], 27)]) def test_get_hkl(self, highest_hkl, n): highest_hkl = np.array(highest_hkl) - with pytest.warns(np.VisibleDeprecationWarning): + with pytest.warns(np.exceptions.VisibleDeprecationWarning): hkl = get_hkl(highest_hkl) assert np.allclose(hkl.max(axis=0), highest_hkl) assert np.allclose(hkl.min(axis=0), -highest_hkl) @@ -52,7 +52,7 @@ def test_get_hkl(self, highest_hkl, n): "d, hkl", [(0.5, [6, 6, 21]), (1, [3, 3, 11]), (1.5, [2, 2, 7])] ) def test_get_highest_hkl(self, silicon_carbide_phase, d, hkl): - with pytest.warns(np.VisibleDeprecationWarning): + with pytest.warns(np.exceptions.VisibleDeprecationWarning): hkl_out = get_highest_hkl( silicon_carbide_phase.structure.lattice, min_dspacing=d ) @@ -64,7 +64,7 @@ def test_get_highest_hkl(self, silicon_carbide_phase, d, hkl): def test_get_equivalent_hkl(self): phase_225 = Phase(space_group=225) - with pytest.warns(np.VisibleDeprecationWarning): + with pytest.warns(np.exceptions.VisibleDeprecationWarning): hkl1 = get_equivalent_hkl( [1, 1, 1], operations=phase_225.point_group, unique=True ) @@ -86,12 +86,12 @@ def test_get_equivalent_hkl(self): g1 = ReciprocalLatticeVector(phase_225, hkl=[1, 1, 1]) assert np.allclose(g1.symmetrise().hkl, hkl1.data) - with pytest.warns(np.VisibleDeprecationWarning): + with pytest.warns(np.exceptions.VisibleDeprecationWarning): hkl2 = get_equivalent_hkl([1, 1, 1], operations=phase_225.point_group) assert hkl2.shape[0] == g1.symmetrise().size * 6 == 48 phase_186 = Phase(space_group=186) - with pytest.warns(np.VisibleDeprecationWarning): + with pytest.warns(np.exceptions.VisibleDeprecationWarning): hkl3, mult3 = get_equivalent_hkl( [2, 2, 0], operations=phase_186.point_group, @@ -102,7 +102,7 @@ def test_get_equivalent_hkl(self): assert mult3 == g3.symmetrise().size == 12 assert np.allclose(hkl3.data[:2], [[2, 2, 0], [-2.7321, 0.7321, 0]], atol=1e-4) - with pytest.warns(np.VisibleDeprecationWarning): + with pytest.warns(np.exceptions.VisibleDeprecationWarning): hkl4, mult4 = get_equivalent_hkl( Vector3d([[2, 2, 0], [4, 0, 0]]), phase_186.point_group, diff --git a/diffsims/tests/utils/test_deprecation.py b/diffsims/tests/utils/test_deprecation.py index e407d9c7..533b1d85 100644 --- a/diffsims/tests/utils/test_deprecation.py +++ b/diffsims/tests/utils/test_deprecation.py @@ -18,7 +18,7 @@ def foo(n): """Some docstring.""" return n + 1 - with pytest.warns(np.VisibleDeprecationWarning) as record: + with pytest.warns(np.exceptions.VisibleDeprecationWarning) as record: assert foo(4) == 5 desired_msg = ( "Function `foo()` is deprecated and will be removed in version 0.8. Use " @@ -41,7 +41,7 @@ def foo2(n): """ return n + 2 - with pytest.warns(np.VisibleDeprecationWarning) as record2: + with pytest.warns(np.exceptions.VisibleDeprecationWarning) as record2: assert foo2(4) == 6 desired_msg2 = "Function `foo2()` is deprecated." assert str(record2[0].message) == desired_msg2 @@ -58,7 +58,7 @@ def test_deprecation_no_old_doc(self): def foo(n): return n + 1 - with pytest.warns(np.VisibleDeprecationWarning) as record: + with pytest.warns(np.exceptions.VisibleDeprecationWarning) as record: assert foo(4) == 5 desired_msg = ( "Function `foo()` is deprecated and will be removed in version 0.8. Use " @@ -79,7 +79,7 @@ def test_deprecation_not_function(self): def foo(n): return n + 1 - with pytest.warns(np.VisibleDeprecationWarning) as record: + with pytest.warns(np.exceptions.VisibleDeprecationWarning) as record: assert foo(4) == 5 desired_msg = ( "Function `foo()` is deprecated and will be removed in version 0.8. Use " @@ -118,7 +118,7 @@ def bar_arg_alt(self, **kwargs): assert my_foo.bar_arg(b=1) == {"b": 1} # Warns - with pytest.warns(np.VisibleDeprecationWarning) as record2: + with pytest.warns(np.exceptions.VisibleDeprecationWarning) as record2: assert my_foo.bar_arg(a=2) == {"a": 2} assert str(record2[0].message) == ( r"Argument `a` is deprecated and will be removed in version 1.4. " @@ -127,7 +127,7 @@ def bar_arg_alt(self, **kwargs): ) # Warns with alternative - with pytest.warns(np.VisibleDeprecationWarning) as record3: + with pytest.warns(np.exceptions.VisibleDeprecationWarning) as record3: assert my_foo.bar_arg_alt(a=3) == {"b": 3} assert str(record3[0].message) == ( r"Argument `a` is deprecated and will be removed in version 1.4. " diff --git a/diffsims/utils/_deprecated.py b/diffsims/utils/_deprecated.py index e0592f08..0a0da6ac 100644 --- a/diffsims/utils/_deprecated.py +++ b/diffsims/utils/_deprecated.py @@ -90,12 +90,14 @@ def __call__(self, func: Callable): @functools.wraps(func) def wrapped(*args, **kwargs): warnings.simplefilter( - action="always", category=np.VisibleDeprecationWarning, append=True + action="always", + category=np.exceptions.VisibleDeprecationWarning, + append=True, ) func_code = func.__code__ warnings.warn_explicit( message=msg, - category=np.VisibleDeprecationWarning, + category=np.exceptions.VisibleDeprecationWarning, filename=func_code.co_filename, lineno=func_code.co_firstlineno + 1, ) @@ -143,12 +145,12 @@ def wrapped(*args, **kwargs): kwargs[self.alternative] = kwargs.pop(self.name) msg += f"See the documentation of `{func.__name__}()` for more details." warnings.simplefilter( - action="always", category=np.VisibleDeprecationWarning + action="always", category=np.exceptions.VisibleDeprecationWarning ) func_code = func.__code__ warnings.warn_explicit( message=msg, - category=np.VisibleDeprecationWarning, + category=np.exceptions.VisibleDeprecationWarning, filename=func_code.co_filename, lineno=func_code.co_firstlineno + 1, )