Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5058c2e

Browse filesBrowse files
committed
Rewrite assert np.* tests to use numpy.testing
1 parent 2193652 commit 5058c2e
Copy full SHA for 5058c2e

File tree

Expand file treeCollapse file tree

6 files changed

+22
-25
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+22
-25
lines changed

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6320,8 +6320,8 @@ def test_hist_nan_data():
63206320
with np.errstate(invalid='ignore'):
63216321
nanbins, nanedges, _ = ax2.hist(nan_data)
63226322

6323-
assert np.allclose(bins, nanbins)
6324-
assert np.allclose(edges, nanedges)
6323+
np.testing.assert_allclose(bins, nanbins)
6324+
np.testing.assert_allclose(edges, nanedges)
63256325

63266326

63276327
def test_hist_range_and_density():

‎lib/matplotlib/tests/test_colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colorbar.py
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,17 @@ def test_colorbar_minorticks_on_off():
320320

321321
# test that minorticks turn off for LogNorm
322322
cbar.minorticks_off()
323-
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
324-
np.array([]))
323+
np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(), [])
325324

326325
# test that minorticks turn back on for LogNorm
327326
cbar.minorticks_on()
328-
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
329-
default_minorticklocks)
327+
np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(),
328+
default_minorticklocks)
330329

331330
# test issue #13339: minorticks for LogNorm should stay off
332331
cbar.minorticks_off()
333332
cbar.set_ticks([3, 5, 7, 9])
334-
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
335-
np.array([]))
333+
np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(), [])
336334

337335

338336
def test_colorbar_autoticks():
@@ -451,23 +449,23 @@ def test_colorbar_renorm():
451449
fig, ax = plt.subplots()
452450
im = ax.imshow(z)
453451
cbar = fig.colorbar(im)
454-
assert np.allclose(cbar.ax.yaxis.get_majorticklocs(),
455-
np.arange(0, 120000.1, 15000))
452+
np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
453+
np.arange(0, 120000.1, 15000))
456454

457455
cbar.set_ticks([1, 2, 3])
458456
assert isinstance(cbar.locator, FixedLocator)
459457

460458
norm = LogNorm(z.min(), z.max())
461459
im.set_norm(norm)
462460
assert isinstance(cbar.locator, _ColorbarLogLocator)
463-
assert np.allclose(cbar.ax.yaxis.get_majorticklocs(),
464-
np.logspace(-8, 5, 14))
461+
np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
462+
np.logspace(-8, 5, 14))
465463
# note that set_norm removes the FixedLocator...
466464
assert np.isclose(cbar.vmin, z.min())
467465
cbar.set_ticks([1, 2, 3])
468466
assert isinstance(cbar.locator, FixedLocator)
469-
assert np.allclose(cbar.ax.yaxis.get_majorticklocs(),
470-
[1.0, 2.0, 3.0])
467+
np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
468+
[1.0, 2.0, 3.0])
471469

472470
norm = LogNorm(z.min() * 1000, z.max() * 1000)
473471
im.set_norm(norm)

‎lib/matplotlib/tests/test_dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_dates.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def test_date_numpyx():
3333
ax = fig.add_subplot(1, 1, 1)
3434
h, = ax.plot(time, data)
3535
hnp, = ax.plot(timenp, data)
36-
assert np.array_equal(h.get_xdata(orig=False), hnp.get_xdata(orig=False))
36+
np.testing.assert_equal(h.get_xdata(orig=False), hnp.get_xdata(orig=False))
3737
fig = plt.figure(figsize=(10, 2))
3838
ax = fig.add_subplot(1, 1, 1)
3939
h, = ax.plot(data, time)
4040
hnp, = ax.plot(data, timenp)
41-
assert np.array_equal(h.get_ydata(orig=False), hnp.get_ydata(orig=False))
41+
np.testing.assert_equal(h.get_ydata(orig=False), hnp.get_ydata(orig=False))
4242

4343

4444
@pytest.mark.parametrize('t0', [datetime.datetime(2017, 1, 1, 0, 1, 1),
@@ -58,7 +58,7 @@ def test_date_date2num_numpy(t0, dtype):
5858
time = mdates.date2num(t0)
5959
tnp = np.array(t0, dtype=dtype)
6060
nptime = mdates.date2num(tnp)
61-
assert np.array_equal(time, nptime)
61+
np.testing.assert_equal(time, nptime)
6262

6363

6464
@pytest.mark.parametrize('dtype', ['datetime64[s]',
@@ -827,4 +827,4 @@ def test_num2timedelta(x, tdelta):
827827
def test_datetime64_in_list():
828828
dt = [np.datetime64('2000-01-01'), np.datetime64('2001-01-01')]
829829
dn = mdates.date2num(dt)
830-
assert np.array_equal(dn, [730120., 730486.])
830+
np.testing.assert_equal(dn, [730120., 730486.])

‎lib/matplotlib/tests/test_path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_path.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ def test_point_in_path():
3838
points = [(0.5, 0.5), (1.5, 0.5)]
3939
ret = path.contains_points(points)
4040
assert ret.dtype == 'bool'
41-
assert np.all(ret == [True, False])
41+
np.testing.assert_equal(ret, [True, False])
4242

4343

4444
def test_contains_points_negative_radius():
4545
path = Path.unit_circle()
4646

4747
points = [(0.0, 0.0), (1.25, 0.0), (0.9, 0.9)]
48-
expected = [True, False, False]
4948
result = path.contains_points(points, radius=-0.5)
50-
51-
assert np.all(result == expected)
49+
np.testing.assert_equal(result, [True, False, False])
5250

5351

5452
def test_point_in_path_nan():
@@ -359,4 +357,4 @@ def test_full_arc(offset):
359357
mins = np.min(path.vertices, axis=0)
360358
maxs = np.max(path.vertices, axis=0)
361359
np.testing.assert_allclose(mins, -1)
362-
assert np.allclose(maxs, 1)
360+
np.testing.assert_allclose(maxs, 1)

‎lib/matplotlib/tests/test_rcparams.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_rcparams.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def generate_validator_testcases(valid):
387387
def test_validator_valid(validator, arg, target):
388388
res = validator(arg)
389389
if isinstance(target, np.ndarray):
390-
assert np.all(res == target)
390+
np.testing.assert_equal(res, target)
391391
elif not isinstance(target, Cycler):
392392
assert res == target
393393
else:

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ def test_low_number_of_majorticks(
125125
def test_using_all_default_major_steps(self):
126126
with matplotlib.rc_context({'_internal.classic_mode': False}):
127127
majorsteps = [x[0] for x in self.majorstep_minordivisions]
128-
assert np.allclose(majorsteps, mticker.AutoLocator()._steps)
128+
np.testing.assert_allclose(majorsteps,
129+
mticker.AutoLocator()._steps)
129130

130131
@pytest.mark.parametrize('major_step, expected_nb_minordivisions',
131132
majorstep_minordivisions)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.