Skip to content

Commit 8e526b9

Browse files
committed
Deprecation: np.VisibleDeprecationsWarning -->np.exceptions.VisibleDeprecationsWarning
1 parent 77aaa31 commit 8e526b9

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

diffsims/tests/crystallography/test_get_hkl.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828
ReciprocalLatticeVector,
2929
)
3030

31+
if np.__version__ >= "2.0.0":
32+
from np.exceptions import VisibleDeprecationWarning
33+
else:
34+
VisibleDeprecationWarning = np.VisibleDeprecationWarning
35+
3136

3237
class TestGetHKL:
3338
@pytest.mark.parametrize("highest_hkl, n", [([1, 2, 3], 105), ([1, 1, 1], 27)])
3439
def test_get_hkl(self, highest_hkl, n):
3540
highest_hkl = np.array(highest_hkl)
36-
with pytest.warns(np.VisibleDeprecationWarning):
41+
with pytest.warns(VisibleDeprecationWarning):
3742
hkl = get_hkl(highest_hkl)
3843
assert np.allclose(hkl.max(axis=0), highest_hkl)
3944
assert np.allclose(hkl.min(axis=0), -highest_hkl)
@@ -52,7 +57,7 @@ def test_get_hkl(self, highest_hkl, n):
5257
"d, hkl", [(0.5, [6, 6, 21]), (1, [3, 3, 11]), (1.5, [2, 2, 7])]
5358
)
5459
def test_get_highest_hkl(self, silicon_carbide_phase, d, hkl):
55-
with pytest.warns(np.VisibleDeprecationWarning):
60+
with pytest.warns(VisibleDeprecationWarning):
5661
hkl_out = get_highest_hkl(
5762
silicon_carbide_phase.structure.lattice, min_dspacing=d
5863
)
@@ -64,7 +69,7 @@ def test_get_highest_hkl(self, silicon_carbide_phase, d, hkl):
6469

6570
def test_get_equivalent_hkl(self):
6671
phase_225 = Phase(space_group=225)
67-
with pytest.warns(np.VisibleDeprecationWarning):
72+
with pytest.warns(VisibleDeprecationWarning):
6873
hkl1 = get_equivalent_hkl(
6974
[1, 1, 1], operations=phase_225.point_group, unique=True
7075
)
@@ -86,12 +91,12 @@ def test_get_equivalent_hkl(self):
8691
g1 = ReciprocalLatticeVector(phase_225, hkl=[1, 1, 1])
8792
assert np.allclose(g1.symmetrise().hkl, hkl1.data)
8893

89-
with pytest.warns(np.VisibleDeprecationWarning):
94+
with pytest.warns(VisibleDeprecationWarning):
9095
hkl2 = get_equivalent_hkl([1, 1, 1], operations=phase_225.point_group)
9196
assert hkl2.shape[0] == g1.symmetrise().size * 6 == 48
9297

9398
phase_186 = Phase(space_group=186)
94-
with pytest.warns(np.VisibleDeprecationWarning):
99+
with pytest.warns(VisibleDeprecationWarning):
95100
hkl3, mult3 = get_equivalent_hkl(
96101
[2, 2, 0],
97102
operations=phase_186.point_group,
@@ -102,7 +107,7 @@ def test_get_equivalent_hkl(self):
102107
assert mult3 == g3.symmetrise().size == 12
103108
assert np.allclose(hkl3.data[:2], [[2, 2, 0], [-2.7321, 0.7321, 0]], atol=1e-4)
104109

105-
with pytest.warns(np.VisibleDeprecationWarning):
110+
with pytest.warns(VisibleDeprecationWarning):
106111
hkl4, mult4 = get_equivalent_hkl(
107112
Vector3d([[2, 2, 0], [4, 0, 0]]),
108113
phase_186.point_group,

diffsims/tests/utils/test_deprecation.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
from diffsims.utils._deprecated import deprecated, deprecated_argument
77

8+
if np.__version__ >= "2.0.0":
9+
from np.exceptions import VisibleDeprecationWarning
10+
else:
11+
VisibleDeprecationWarning = np.VisibleDeprecationWarning
12+
813

914
class TestDeprecationWarning:
1015
def test_deprecation_since(self):
@@ -18,7 +23,7 @@ def foo(n):
1823
"""Some docstring."""
1924
return n + 1
2025

21-
with pytest.warns(np.VisibleDeprecationWarning) as record:
26+
with pytest.warns(VisibleDeprecationWarning) as record:
2227
assert foo(4) == 5
2328
desired_msg = (
2429
"Function `foo()` is deprecated and will be removed in version 0.8. Use "
@@ -41,7 +46,7 @@ def foo2(n):
4146
"""
4247
return n + 2
4348

44-
with pytest.warns(np.VisibleDeprecationWarning) as record2:
49+
with pytest.warns(VisibleDeprecationWarning) as record2:
4550
assert foo2(4) == 6
4651
desired_msg2 = "Function `foo2()` is deprecated."
4752
assert str(record2[0].message) == desired_msg2
@@ -58,7 +63,7 @@ def test_deprecation_no_old_doc(self):
5863
def foo(n):
5964
return n + 1
6065

61-
with pytest.warns(np.VisibleDeprecationWarning) as record:
66+
with pytest.warns(VisibleDeprecationWarning) as record:
6267
assert foo(4) == 5
6368
desired_msg = (
6469
"Function `foo()` is deprecated and will be removed in version 0.8. Use "
@@ -79,7 +84,7 @@ def test_deprecation_not_function(self):
7984
def foo(n):
8085
return n + 1
8186

82-
with pytest.warns(np.VisibleDeprecationWarning) as record:
87+
with pytest.warns(VisibleDeprecationWarning) as record:
8388
assert foo(4) == 5
8489
desired_msg = (
8590
"Function `foo()` is deprecated and will be removed in version 0.8. Use "
@@ -118,7 +123,7 @@ def bar_arg_alt(self, **kwargs):
118123
assert my_foo.bar_arg(b=1) == {"b": 1}
119124

120125
# Warns
121-
with pytest.warns(np.VisibleDeprecationWarning) as record2:
126+
with pytest.warns(VisibleDeprecationWarning) as record2:
122127
assert my_foo.bar_arg(a=2) == {"a": 2}
123128
assert str(record2[0].message) == (
124129
r"Argument `a` is deprecated and will be removed in version 1.4. "
@@ -127,7 +132,7 @@ def bar_arg_alt(self, **kwargs):
127132
)
128133

129134
# Warns with alternative
130-
with pytest.warns(np.VisibleDeprecationWarning) as record3:
135+
with pytest.warns(VisibleDeprecationWarning) as record3:
131136
assert my_foo.bar_arg_alt(a=3) == {"b": 3}
132137
assert str(record3[0].message) == (
133138
r"Argument `a` is deprecated and will be removed in version 1.4. "

diffsims/utils/_deprecated.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535

3636
import numpy as np
3737

38+
if np.__version__ >= "2.0.0":
39+
from np.exceptions import VisibleDeprecationWarning
40+
else:
41+
VisibleDeprecationWarning = np.VisibleDeprecationWarning
42+
3843

3944
class deprecated:
4045
"""Decorator to mark deprecated functions with an informative
@@ -90,12 +95,14 @@ def __call__(self, func: Callable):
9095
@functools.wraps(func)
9196
def wrapped(*args, **kwargs):
9297
warnings.simplefilter(
93-
action="always", category=np.VisibleDeprecationWarning, append=True
98+
action="always",
99+
category=VisibleDeprecationWarning,
100+
append=True,
94101
)
95102
func_code = func.__code__
96103
warnings.warn_explicit(
97104
message=msg,
98-
category=np.VisibleDeprecationWarning,
105+
category=VisibleDeprecationWarning,
99106
filename=func_code.co_filename,
100107
lineno=func_code.co_firstlineno + 1,
101108
)
@@ -143,12 +150,12 @@ def wrapped(*args, **kwargs):
143150
kwargs[self.alternative] = kwargs.pop(self.name)
144151
msg += f"See the documentation of `{func.__name__}()` for more details."
145152
warnings.simplefilter(
146-
action="always", category=np.VisibleDeprecationWarning
153+
action="always", category=VisibleDeprecationWarning
147154
)
148155
func_code = func.__code__
149156
warnings.warn_explicit(
150157
message=msg,
151-
category=np.VisibleDeprecationWarning,
158+
category=VisibleDeprecationWarning,
152159
filename=func_code.co_filename,
153160
lineno=func_code.co_firstlineno + 1,
154161
)

0 commit comments

Comments
 (0)