@@ -229,8 +229,32 @@ slice_coerce_index(PyObject *o, npy_intp *v)
229
229
return 1 ;
230
230
}
231
231
232
- /* This is basically PySlice_GetIndicesEx, but with our coercion
233
- * of indices to integers (plus, that function is new in Python 2.3) */
232
+ /*
233
+ * Issue a DeprecationWarning for slice parameters that do not pass a
234
+ * PyIndex_Check, returning -1 if an error occurs.
235
+ *
236
+ * N.B. This function, like slice_GetIndices, will be obsolete once
237
+ * non-integer slice parameters becomes an error rather than a warning.
238
+ */
239
+ static NPY_INLINE int
240
+ _validate_slice_parameter (PyObject * o )
241
+ {
242
+ if (!PyIndex_Check_Or_Unsupported (o )) {
243
+ if (DEPRECATE ("non-integer slice parameter. In a future numpy "
244
+ "release, this will raise an error." ) < 0 ) {
245
+ return -1 ;
246
+ }
247
+ }
248
+ return 0 ;
249
+ }
250
+
251
+ /*
252
+ * This is basically PySlice_GetIndicesEx, but with our coercion
253
+ * of indices to integers (plus, that function is new in Python 2.3)
254
+ *
255
+ * N.B. The coercion to integers is deprecated; once the DeprecationWarning
256
+ * is changed to an error, it would seem that this is obsolete.
257
+ */
234
258
NPY_NO_EXPORT int
235
259
slice_GetIndices (PySliceObject * r , npy_intp length ,
236
260
npy_intp * start , npy_intp * stop , npy_intp * step ,
@@ -242,6 +266,9 @@ slice_GetIndices(PySliceObject *r, npy_intp length,
242
266
* step = 1 ;
243
267
}
244
268
else {
269
+ if (_validate_slice_parameter (r -> step ) < 0 ) {
270
+ return -1 ;
271
+ }
245
272
if (!slice_coerce_index (r -> step , step )) {
246
273
return -1 ;
247
274
}
@@ -257,6 +284,9 @@ slice_GetIndices(PySliceObject *r, npy_intp length,
257
284
* start = * step < 0 ? length - 1 : 0 ;
258
285
}
259
286
else {
287
+ if (_validate_slice_parameter (r -> start ) < 0 ) {
288
+ return -1 ;
289
+ }
260
290
if (!slice_coerce_index (r -> start , start )) {
261
291
return -1 ;
262
292
}
@@ -275,6 +305,9 @@ slice_GetIndices(PySliceObject *r, npy_intp length,
275
305
* stop = defstop ;
276
306
}
277
307
else {
308
+ if (_validate_slice_parameter (r -> stop ) < 0 ) {
309
+ return -1 ;
310
+ }
278
311
if (!slice_coerce_index (r -> stop , stop )) {
279
312
return -1 ;
280
313
}
0 commit comments