@@ -2166,7 +2166,7 @@ def pts_to_prestep(x, *args):
2166
2166
Parameters
2167
2167
----------
2168
2168
x : array
2169
- The x location of the steps.
2169
+ The x location of the steps. May be empty.
2170
2170
2171
2171
y1, ..., yp : array
2172
2172
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):
2176
2176
out : array
2177
2177
The x and y values converted to steps in the same order as the input;
2178
2178
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.
2180
2181
2181
2182
Examples
2182
2183
--------
2183
2184
>> x_s, y1_s, y2_s = pts_to_prestep(x, y1, y2)
2184
2185
"""
2185
- steps = np .zeros ((1 + len (args ), 2 * len (x ) - 1 ))
2186
+ steps = np .zeros ((1 + len (args ), max ( 2 * len (x ) - 1 , 0 ) ))
2186
2187
# In all `pts_to_*step` functions, only assign *once* using `x` and `args`,
2187
2188
# as converting to an array may be expensive.
2188
2189
steps [0 , 0 ::2 ] = x
@@ -2203,7 +2204,7 @@ def pts_to_poststep(x, *args):
2203
2204
Parameters
2204
2205
----------
2205
2206
x : array
2206
- The x location of the steps.
2207
+ The x location of the steps. May be empty.
2207
2208
2208
2209
y1, ..., yp : array
2209
2210
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):
2213
2214
out : array
2214
2215
The x and y values converted to steps in the same order as the input;
2215
2216
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.
2217
2219
2218
2220
Examples
2219
2221
--------
2220
2222
>> x_s, y1_s, y2_s = pts_to_poststep(x, y1, y2)
2221
2223
"""
2222
- steps = np .zeros ((1 + len (args ), 2 * len (x ) - 1 ))
2224
+ steps = np .zeros ((1 + len (args ), max ( 2 * len (x ) - 1 , 0 ) ))
2223
2225
steps [0 , 0 ::2 ] = x
2224
2226
steps [0 , 1 ::2 ] = steps [0 , 2 ::2 ]
2225
2227
steps [1 :, 0 ::2 ] = args
@@ -2238,7 +2240,7 @@ def pts_to_midstep(x, *args):
2238
2240
Parameters
2239
2241
----------
2240
2242
x : array
2241
- The x location of the steps.
2243
+ The x location of the steps. May be empty.
2242
2244
2243
2245
y1, ..., yp : array
2244
2246
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):
2257
2259
steps = np .zeros ((1 + len (args ), 2 * len (x )))
2258
2260
x = np .asanyarray (x )
2259
2261
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 :]
2261
2264
steps [1 :, 0 ::2 ] = args
2262
2265
steps [1 :, 1 ::2 ] = steps [1 :, 0 ::2 ]
2263
2266
return steps
0 commit comments