@@ -2166,7 +2166,7 @@ def pts_to_prestep(x, *args):
21662166 Parameters
21672167 ----------
21682168 x : array
2169- The x location of the steps.
2169+ The x location of the steps. May be empty.
21702170
21712171 y1, ..., yp : array
21722172 y arrays to be turned into steps; all must be the same length as ``x``.
@@ -2176,13 +2176,14 @@ def pts_to_prestep(x, *args):
21762176 out : array
21772177 The x and y values converted to steps in the same order as the input;
21782178 can be unpacked as ``x_out, y1_out, ..., yp_out``. If the input is
2179- length ``N``, each of these arrays will be length ``2N + 1``.
2179+ length ``N``, each of these arrays will be length ``2N + 1``. For
2180+ ``N=0``, the length will be 0.
21802181
21812182 Examples
21822183 --------
21832184 >> x_s, y1_s, y2_s = pts_to_prestep(x, y1, y2)
21842185 """
2185- steps = np .zeros ((1 + len (args ), 2 * len (x ) - 1 ))
2186+ steps = np .zeros ((1 + len (args ), max ( 2 * len (x ) - 1 , <
F440
/span>0 ) ))
21862187 # In all `pts_to_*step` functions, only assign *once* using `x` and `args`,
21872188 # as converting to an array may be expensive.
21882189 steps [0 , 0 ::2 ] = x
@@ -2203,7 +2204,7 @@ def pts_to_poststep(x, *args):
22032204 Parameters
22042205 ----------
22052206 x : array
2206- The x location of the steps.
2207+ The x location of the steps. May be empty.
22072208
22082209 y1, ..., yp : array
22092210 y arrays to be turned into steps; all must be the same length as ``x``.
@@ -2213,13 +2214,14 @@ def pts_to_poststep(x, *args):
22132214 out : array
22142215 The x and y values converted to steps in the same order as the input;
22152216 can be unpacked as ``x_out, y1_out, ..., yp_out``. If the input is
2216- length ``N``, each of these arrays will be length ``2N + 1``.
2217+ length ``N``, each of these arrays will be length ``2N + 1``. For
2218+ ``N=0``, the length will be 0.
22172219
22182220 Examples
22192221 --------
22202222 >> x_s, y1_s, y2_s = pts_to_poststep(x, y1, y2)
22212223 """
2222- steps = np .zeros ((1 + len (args ), 2 * len (x ) - 1 ))
2224+ steps = np .zeros ((1 + len (args ), max ( 2 * len (x ) - 1 , 0 ) ))
22232225 steps [0 , 0 ::2 ] = x
22242226 steps [0 , 1 ::2 ] = steps [0 , 2 ::2 ]
22252227 steps [1 :, 0 ::2 ] = args
@@ -2238,7 +2240,7 @@ def pts_to_midstep(x, *args):
22382240 Parameters
22392241 ----------
22402242 x : array
2241- The x location of the steps.
2243+ The x location of the steps. May be empty.
22422244
22432245 y1, ..., yp : array
22442246 y arrays to be turned into steps; all must be the same length as ``x``.
@@ -2257,7 +2259,8 @@ def pts_to_midstep(x, *args):
22572259 steps = np .zeros ((1 + len (args ), 2 * len (x )))
22582260 x = np .asanyarray (x )
22592261 steps [0 , 1 :- 1 :2 ] = steps [0 , 2 ::2 ] = (x [:- 1 ] + x [1 :]) / 2
2260- steps [0 , 0 ], steps [0 , - 1 ] = x [0 ], x [- 1 ]
2262+ steps [0 , :1 ] = x [:1 ] # Also works for zero-sized input.
2263+ steps [0 , - 1 :] = x [- 1 :]
22612264 steps [1 :, 0 ::2 ] = args
22622265 steps [1 :, 1 ::2 ] = steps [1 :, 0 ::2 ]
22632266 return steps
0 commit comments