Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd250ac

Browse files
committed
add tests for pts_to_pre/mid/poststep() with empty args
1 parent 3fbdd8a commit cd250ac

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

lib/matplotlib/cbook/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,7 @@ def pts_to_prestep(x, *args):
21672167
Parameters
21682168
----------
21692169
x : array
2170-
The x location of the steps.
2170+
The x location of the steps. May be empty.
21712171
21722172
y1, ..., yp : array
21732173
y arrays to be turned into steps; all must be the same length as ``x``.
@@ -2177,7 +2177,8 @@ def pts_to_prestep(x, *args):
21772177
out : array
21782178
The x and y values converted to steps in the same order as the input;
21792179
can be unpacked as ``x_out, y1_out, ..., yp_out``. If the input is
2180-
length ``N``, each of these arrays will be length ``2N + 1``.
2180+
length ``N``, each of these arrays will be length ``2N + 1``. For
2181+
``N=0``, the length will be 0.
21812182
21822183
Examples
21832184
--------
@@ -2204,7 +2205,7 @@ def pts_to_poststep(x, *args):
22042205
Parameters
22052206
----------
22062207
x : array
2207-
The x location of the steps.
2208+
The x location of the steps. May be empty.
22082209
22092210
y1, ..., yp : array
22102211
y arrays to be turned into steps; all must be the same length as ``x``.
@@ -2214,7 +2215,8 @@ def pts_to_poststep(x, *args):
22142215
out : array
22152216
The x and y values converted to steps in the same order as the input;
22162217
can be unpacked as ``x_out, y1_out, ..., yp_out``. If the input is
2217-
length ``N``, each of these arrays will be length ``2N + 1``.
2218+
length ``N``, each of these arrays will be length ``2N + 1``. For
2219+
``N=0``, the length will be 0.
22182220
22192221
Examples
22202222
--------
@@ -2239,7 +2241,7 @@ def pts_to_midstep(x, *args):
22392241
Parameters
22402242
----------
22412243
x : array
2242-
The x location of the steps.
2244+
The x location of the steps. May be empty.
22432245
22442246
y1, ..., yp : array
22452247
y arrays to be turned into steps; all must be the same length as ``x``.

lib/matplotlib/tests/test_cbook.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ def test_to_prestep():
392392
assert_array_equal(y1_target, y1s)
393393

394394

395+
def test_to_prestep_empty():
396+
steps = cbook.pts_to_prestep([], [])
397+
assert steps.shape == (2, 0)
398+
399+
395400
def test_to_poststep():
396401
x = np.arange(4)
397402
y1 = np.arange(4)
@@ -412,6 +417,11 @@ def test_to_poststep():
412417
assert_array_equal(y1_target, y1s)
413418

414419

420+
def test_to_poststep_empty():
421+
steps = cbook.pts_to_poststep([], [])
422+
assert steps.shape == (2, 0)
423+
424+
415425
def test_to_midstep():
416426
x = np.arange(4)
417427
y1 = np.arange(4)
@@ -432,6 +442,11 @@ def test_to_midstep():
432442
assert_array_equal(y1_target, y1s)
433443

434444

445+
def test_to_midstep_empty():
446+
steps = cbook.pts_to_midstep([], [])
447+
assert steps.shape == (2, 0)
448+
449+
435450
@pytest.mark.parametrize(
436451
"args",
437452
[(np.arange(12).reshape(3, 4), 'a'),

0 commit comments

Comments
 (0)