| 2226 | } |
| 2227 | |
| 2228 | static PyObject * |
| 2229 | npyiter_subscript(NewNpyArrayIterObject *self, PyObject *op) |
| 2230 | { |
| 2231 | if (self->iter == NULL || self->finished) { |
| 2232 | PyErr_SetString(PyExc_ValueError, |
| 2233 | "Iterator is past the end"); |
| 2234 | return NULL; |
| 2235 | } |
| 2236 | |
| 2237 | if (NpyIter_HasDelayedBufAlloc(self->iter)) { |
| 2238 | PyErr_SetString(PyExc_ValueError, |
| 2239 | "Iterator construction used delayed buffer allocation, " |
| 2240 | "and no reset has been done yet"); |
| 2241 | return NULL; |
| 2242 | } |
| 2243 | |
| 2244 | if (PyLong_Check(op) || |
| 2245 | (PyIndex_Check(op) && !PySequence_Check(op))) { |
| 2246 | npy_intp i = PyArray_PyIntAsIntp(op); |
| 2247 | if (error_converting(i)) { |
| 2248 | return NULL; |
| 2249 | } |
| 2250 | return npyiter_seq_item(self, i); |
| 2251 | } |
| 2252 | else if (PySlice_Check(op)) { |
| 2253 | Py_ssize_t istart = 0, iend = 0, istep = 0, islicelength; |
| 2254 | if (PySlice_GetIndicesEx(op, NpyIter_GetNOp(self->iter), |
| 2255 | &istart, &iend, &istep, &islicelength) < 0) { |
| 2256 | return NULL; |
| 2257 | } |
| 2258 | if (istep != 1) { |
| 2259 | PyErr_SetString(PyExc_ValueError, |
| 2260 | "Iterator slicing only supports a step of 1"); |
| 2261 | return NULL; |
| 2262 | } |
| 2263 | return npyiter_seq_slice(self, istart, iend); |
| 2264 | } |
| 2265 | |
| 2266 | PyErr_SetString(PyExc_TypeError, |
| 2267 | "invalid index type for iterator indexing"); |
| 2268 | return NULL; |
| 2269 | } |
| 2270 | |
| 2271 | static int |
| 2272 | npyiter_ass_subscript(NewNpyArrayIterObject *self, PyObject *op, |
nothing calls this directly
no test coverage detected