Skip to content

Commit 4c92343

Browse files
committed
Import NumPy more consistently in tests.
1 parent 52e04f5 commit 4c92343

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import numpy as np
21
from io import BytesIO
32
import re
43
import tempfile
54
import xml.parsers.expat
65

6+
import numpy as np
77
import pytest
88

99
import matplotlib as mpl

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import numpy as np
21
from io import BytesIO
32

3+
import numpy as np
4+
45
from matplotlib.testing.decorators import image_comparison
56
import matplotlib.pyplot as plt
67
import matplotlib.path as mpath

lib/matplotlib/tests/test_image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import urllib.request
99

1010
import numpy as np
11-
from numpy import ma
1211
from numpy.testing import assert_array_equal
1312
from PIL import Image
1413

@@ -820,7 +819,7 @@ def test_mask_image_over_under():
820819
palette.set_over('r', 1.0)
821820
palette.set_under('g', 1.0)
822821
palette.set_bad('b', 1.0)
823-
Zm = ma.masked_where(Z > 1.2, Z)
822+
Zm = np.ma.masked_where(Z > 1.2, Z)
824823
fig, (ax1, ax2) = plt.subplots(1, 2)
825824
im = ax1.imshow(Zm, interpolation='bilinear',
826825
cmap=palette,

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from collections import namedtuple
2-
import numpy.testing as nptest
2+
3+
from numpy.testing import assert_allclose
34
import pytest
5+
46
from matplotlib.testing.decorators import image_comparison
57
import matplotlib.pyplot as plt
68
import matplotlib.patches as mpatches
@@ -143,7 +145,7 @@ def test_get_packed_offsets(wd_list, total, sep, mode):
143145
def test_get_packed_offsets_fixed(wd_list, total, sep, expected):
144146
result = _get_packed_offsets(wd_list, total, sep, mode='fixed')
145147
assert result[0] == expected[0]
146-
nptest.assert_allclose(result[1], expected[1])
148+
assert_allclose(result[1], expected[1])
147149

148150

149151
@pytest.mark.parametrize('wd_list, total, sep, expected', [
@@ -157,7 +159,7 @@ def test_get_packed_offsets_fixed(wd_list, total, sep, expected):
157159
def test_get_packed_offsets_expand(wd_list, total, sep, expected):
158160
result = _get_packed_offsets(wd_list, total, sep, mode='expand')
159161
assert result[0] == expected[0]
160-
nptest.assert_allclose(result[1], expected[1])
162+
assert_allclose(result[1], expected[1])
161163

162164

163165
@pytest.mark.parametrize('wd_list, total, sep, expected', [
@@ -174,7 +176,7 @@ def test_get_packed_offsets_expand(wd_list, total, sep, expected):
174176
def test_get_packed_offsets_equal(wd_list, total, sep, expected):
175177
result = _get_packed_offsets(wd_list, total, sep, mode='equal')
176178
assert result[0] == expected[0]
177-
nptest.assert_allclose(result[1], expected[1])
179+
assert_allclose(result[1], expected[1])
178180

179181

180182
def test_get_packed_offsets_equal_total_none_sep_none():

lib/matplotlib/tests/test_subplots.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import itertools
22

3-
import numpy
3+
import numpy as np
4+
import pytest
5+
46
import matplotlib.pyplot as plt
57
from matplotlib.testing.decorators import image_comparison
68

7-
import pytest
8-
99

1010
def check_shared(axs, x_shared, y_shared):
1111
"""
@@ -38,14 +38,14 @@ def check_visible(axs, x_visible, y_visible):
3838
def test_shared():
3939
rdim = (4, 4, 2)
4040
share = {
41-
'all': numpy.ones(rdim[:2], dtype=bool),
42-
'none': numpy.zeros(rdim[:2], dtype=bool),
43-
'row': numpy.array([
41+
'all': np.ones(rdim[:2], dtype=bool),
42+
'none': np.zeros(rdim[:2], dtype=bool),
43+
'row': np.array([
4444
[False, True, False, False],
4545
[True, False, False, False],
4646
[False, False, False, True],
4747
[False, False, True, False]]),
48-
'col': numpy.array([
48+
'col': np.array([
4949
[False, False, True, False],
5050
[False, False, False, True],
5151
[True, False, False, False],
@@ -151,8 +151,8 @@ def test_exceptions():
151151

152152
@image_comparison(['subplots_offset_text'], remove_text=False)
153153
def test_subplots_offsettext():
154-
x = numpy.arange(0, 1e10, 1e9)
155-
y = numpy.arange(0, 100, 10)+1e4
154+
x = np.arange(0, 1e10, 1e9)
155+
y = np.arange(0, 100, 10)+1e4
156156
fig, axs = plt.subplots(2, 2, sharex='col', sharey='all')
157157
axs[0, 0].plot(x, x)
158158
axs[1, 0].plot(x, x)

0 commit comments

Comments
 (0)