8000 Merge pull request #14377 from timhoffm/numpy-testing · matplotlib/matplotlib@14228f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14228f0

Browse files
authored
Merge pull request #14377 from timhoffm/numpy-testing
Rewrite assert np.* tests to use numpy.testing
2 parents d8ceee6 + 5058c2e commit 14228f0

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6339,8 +6339,8 @@ def test_hist_nan_data():
63396339
with np.errstate(invalid='ignore'):
63406340
nanbins, nanedges, _ = ax2.hist(nan_data)
63416341

6342-
assert np.allclose(bins, nanbins)
6343-
assert np.allclose(edges, nanedges)
6342+
np.testing.assert_allclose(bins, nanbins)
6343+
np.testing.assert_allclose(edges, nanedges)
63446344

63456345

63466346
def test_hist_range_and_density():

lib/matplotlib/tests/test_colorbar.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,17 @@ def test_colorbar_minorticks_on_off():
313313

314314
# test that minorticks turn off for LogNorm
315315
cbar.minorticks_off()
316-
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
317-
np.array([]))
316+
np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(), [])
318317

319318
# test that minorticks turn back on for LogNorm
320319
cbar.minorticks_on()
321-
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
322-
default_minorticklocks)
320+
np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(),
321+
default_minorticklocks)
323322

324323
# test issue #13339: minorticks for LogNorm should stay off
325324
cbar.minorticks_off()
326325
cbar.set_ticks([3, 5, 7, 9])
327-
assert np.array_equal(cbar.ax.yaxis.get_minorticklocs(),
328-
np.array([]))
326+
np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(), [])
329327

330328

331329
def test_colorbar_autoticks():
@@ -444,23 +442,23 @@ def test_colorbar_renorm():
444442
fig, ax = plt.subplots()
445443
im = ax.imshow(z)
446444
cbar = fig.colorbar(im)
447-
assert np.allclose(cbar.ax.yaxis.get_majorticklocs(),
448-
np.arange(0, 120000.1, 15000))
445+
np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
446+
np.arange(0, 120000.1, 15000))
449447

450448
cbar.set_ticks([1, 2, 3])
451449
assert isinstance(cbar.locator, FixedLocator)
452450

453451
norm = LogNorm(z.min(), z.max())
454452
im.set_norm(norm)
455453
assert isinstance(cbar.locator, _ColorbarLogLocator)
456-
assert np.allclose(cbar.ax.yaxis.get_majorticklocs(),
457-
np.logspace(-8, 5, 14))
454+
np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
455+
np.logspace(-8, 5, 14))
458456
# note that set_norm removes the FixedLocator...
459457
assert np.isclose(cbar.vmin, z.min())
460458
cbar.set_ticks([1, 2, 3])
461459
assert isinstance(cbar.locator, FixedLocator)
462-
assert np.allclose(cbar.ax.yaxis.get_majorticklocs(),
463-
[1.0, 2.0, 3.0])
460+
np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
461+
[1.0, 2.0, 3.0])
464462

465463
norm = LogNorm(z.min() * 1000, z.max() * 1000)
466464
im.set_norm(norm)

lib/matplotlib/tests/test_dates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def test_date_numpyx():
2525
ax = fig.add_subplot(1, 1, 1)
2626
h, = ax.plot(time, data)
2727
hnp, = ax.plot(timenp, data)
28-
assert np.array_equal(h.get_xdata(orig=False), hnp.get_xdata(orig=False))
28+
np.testing.assert_equal(h.get_xdata(orig=False), hnp.get_xdata(orig=False))
2929
fig = plt.figure(figsize=(10, 2))
3030
ax = fig.add_subplot(1, 1, 1)
3131
h, = ax.plot(data, time)
3232
hnp, = ax.plot(data, timenp)
33-
assert np.array_equal(h.get_ydata(orig=False), hnp.get_ydata(orig=False))
33+
np.testing.assert_equal(h.get_ydata(orig=False), hnp.get_ydata(orig=False))
3434

3535

3636
@pytest.mark.parametrize('t0', [datetime.datetime(2017, 1, 1, 0, 1, 1),
@@ -50,7 +50,7 @@ def test_date_date2num_numpy(t0, dtype):
5050
time = mdates.date2num(t0)
5151
tnp = np.array(t0, dtype=dtype)
5252
nptime = mdates.date2num(tnp)
53-
assert np.array_equal(time, nptime)
53+
np.testing.assert_equal(time, nptime)
5454

5555

5656
@pytest.mark.parametrize('dtype', ['datetime64[s]',
@@ -764,4 +764,4 @@ def test_num2timedelta(x, tdelta):
764764
def test_datetime64_in_list():
765765
dt = [np.datetime64('2000-01-01'), np.datetime64('2001-01-01')]
766766
dn = mdates.date2num(dt)
767-
assert np.array_equal(dn, [730120., 730486.])
767+
np.testing.assert_equal(dn, [730120., 730486.])

lib/matplotlib/tests/test_path.py

Lines 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():
@@ -353,4 +351,4 @@ def test_full_arc(offset):
353351
mins = np.min(path.vertices, axis=0)
354352
maxs = np.max(path.vertices, axis=0)
355353
np.testing.assert_allclose(mins, -1)
356-
assert np.allclose(maxs, 1)
354+
np.testing.assert_allclose(maxs, 1)

lib/matplotlib/tests/test_rcparams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def generate_validator_testcases(valid):
391391
def test_validator_valid(validator, arg, target):
392392
res = validator(arg)
393393
if isinstance(target, np.ndarray):
394-
assert np.all(res == target)
394+
np.testing.assert_equal(res, target)
395395
elif not isinstance(target, Cycler):
396396
assert res == target
397397
else:

lib/matplotlib/tests/test_ticker.py

Lines 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