Skip to content

Commit 994f8a1

Browse files
committed
MAINT: Remove __setslice__ and __getslice__
This code was only here for Python 2.5 compatibility, but numpy requires 2.7 at minimum
1 parent 98b3127 commit 994f8a1

9 files changed

Lines changed: 5 additions & 133 deletions

File tree

‎doc/source/reference/arrays.ndarray.rst‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,6 @@ Container customization: (see :ref:`Indexing <arrays.indexing>`)
595595
ndarray.__len__
596596
ndarray.__getitem__
597597
ndarray.__setitem__
598-
ndarray.__getslice__
599-
ndarray.__setslice__
600598
ndarray.__contains__
601599

602600
Conversion; the operations :func:`complex()`, :func:`int()`,

‎doc/source/reference/maskedarray.baseclass.rst‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ Container customization: (see :ref:`Indexing <arrays.indexing>`)
417417
MaskedArray.__getitem__
418418
MaskedArray.__setitem__
419419
MaskedArray.__delitem__
420-
MaskedArray.__getslice__
421-
MaskedArray.__setslice__
422420
MaskedArray.__contains__
423421

424422

‎numpy/core/src/multiarray/nditer_pywrap.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,9 +2416,9 @@ NPY_NO_EXPORT PySequenceMethods npyiter_as_sequence = {
24162416
(binaryfunc)NULL, /*sq_concat*/
24172417
(ssizeargfunc)NULL, /*sq_repeat*/
24182418
(ssizeargfunc)npyiter_seq_item, /*sq_item*/
2419-
(ssizessizeargfunc)npyiter_seq_slice, /*sq_slice*/
2419+
(ssizessizeargfunc)NULL, /*sq_slice*/
24202420
(ssizeobjargproc)npyiter_seq_ass_item, /*sq_ass_item*/
2421-
(ssizessizeobjargproc)npyiter_seq_ass_slice,/*sq_ass_slice*/
2421+
(ssizessizeobjargproc)NULL, /*sq_ass_slice*/
24222422
(objobjproc)NULL, /*sq_contains */
24232423
(binaryfunc)NULL, /*sq_inplace_concat */
24242424
(ssizeargfunc)NULL, /*sq_inplace_repeat */

‎numpy/core/src/multiarray/sequence.c‎

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -27,90 +27,6 @@ array_any_nonzero(PyArrayObject *mp);
2727
we fill it in here so that PySequence_XXXX calls work as expected
2828
*/
2929

30-
31-
static PyObject *
32-
array_slice(PyArrayObject *self, Py_ssize_t ilow, Py_ssize_t ihigh)
33-
{
34-
PyArrayObject *ret;
35-
PyArray_Descr *dtype;
36-
Py_ssize_t dim0;
37-
char *data;
38-
npy_intp shape[NPY_MAXDIMS];
39-
40-
if (PyArray_NDIM(self) == 0) {
41-
PyErr_SetString(PyExc_ValueError, "cannot slice a 0-d array");
42-
return NULL;
43-
}
44-
45-
dim0 = PyArray_DIM(self, 0);
46-
if (ilow < 0) {
47-
ilow = 0;
48-
}
49-
else if (ilow > dim0) {
50-
ilow = dim0;
51-
}
52-
if (ihigh < ilow) {
53-
ihigh = ilow;
54-
}
55-
else if (ihigh > dim0) {
56-
ihigh = dim0;
57-
}
58-
59-
data = PyArray_DATA(self);
60-
if (ilow < ihigh) {
61-
data += ilow * PyArray_STRIDE(self, 0);
62-
}
63-
64-
/* Same shape except dimension 0 */
65-
shape[0] = ihigh - ilow;
66-
memcpy(shape+1, PyArray_DIMS(self) + 1,
67-
(PyArray_NDIM(self)-1)*sizeof(npy_intp));
68-
69-
dtype = PyArray_DESCR(self);
70-
Py_INCREF(dtype);
71-
ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self), dtype,
72-
PyArray_NDIM(self), shape,
73-
PyArray_STRIDES(self), data,
74-
PyArray_FLAGS(self),
75-
(PyObject *)self);
76-
if (ret == NULL) {
77-
return NULL;
78-
}
79-
Py_INCREF(self);
80-
if (PyArray_SetBaseObject(ret, (PyObject *)self) < 0) {
81-
Py_DECREF(ret);
82-
return NULL;
83-
}
84-
PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL);
85-
86-
return (PyObject *)ret;
87-
}
88-
89-
90-
static int
91-
array_assign_slice(PyArrayObject *self, Py_ssize_t ilow,
92-
Py_ssize_t ihigh, PyObject *v) {
93-
int ret;
94-
PyArrayObject *tmp;
95-
96-
if (v == NULL) {
97-
PyErr_SetString(PyExc_ValueError,
98-
"cannot delete array elements");
99-
return -1;
100-
}
101-
if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) {
102-
return -1;
103-
}
104-
tmp = (PyArrayObject *)array_slice(self, ilow, ihigh);
105-
if (tmp == NULL) {
106-
return -1;
107-
}
108-
ret = PyArray_CopyObject(tmp, v);
109-
Py_DECREF(tmp);
110-
111-
return ret;
112-
}
113-
11430
static int
11531
array_contains(PyArrayObject *self, PyObject *el)
11632
{
@@ -134,9 +50,9 @@ NPY_NO_EXPORT PySequenceMethods array_as_sequence = {
13450
(binaryfunc)NULL, /*sq_concat is handled by nb_add*/
13551
(ssizeargfunc)NULL,
13652
(ssizeargfunc)array_item,
137-
(ssizessizeargfunc)array_slice,
138-
(ssizeobjargproc)array_assign_item, /*sq_ass_item*/
139-
(ssizessizeobjargproc)array_assign_slice, /*sq_ass_slice*/
53+
(ssizessizeargfunc)NULL,
54+
(ssizeobjargproc)array_assign_item, /*sq_ass_item*/
55+
(ssizessizeobjargproc)NULL, /*sq_ass_slice*/
14056
(objobjproc) array_contains, /*sq_contains */
14157
(binaryfunc) NULL, /*sg_inplace_concat */
14258
(ssizeargfunc)NULL,

‎numpy/lib/index_tricks.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ def __getitem__(self, key):
209209
else:
210210
return _nx.arange(start, stop, step)
211211

212-
def __getslice__(self, i, j):
213-
return _nx.arange(i, j)
214-
215212
def __len__(self):
216213
return 0
217214

@@ -338,10 +335,6 @@ def __getitem__(self, key):
338335
res = _nx.concatenate(tuple(objs), axis=self.axis)
339336
return self._retval(res)
340337

341-
def __getslice__(self, i, j):
342-
res = _nx.arange(i, j)
343-
return self._retval(res)
344-
345338
def __len__(self):
346339
return 0
347340

‎numpy/lib/user_array.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,9 @@ def __len__(self):
5151
def __getitem__(self, index):
5252
return self._rc(self.array[index])
5353

54-
def __getslice__(self, i, j):
55-
return self._rc(self.array[i:j])
56-
5754
def __setitem__(self, index, value):
5855
self.array[index] = asarray(value, self.dtype)
5956

60-
def __setslice__(self, i, j, value):
61-
self.array[i:j] = asarray(value, self.dtype)
62-
6357
def __abs__(self):
6458
return self._rc(absolute(self.array))
6559

‎numpy/ma/core.py‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,26 +3331,6 @@ def __setattr__(self, attr, value):
33313331
except (AttributeError, TypeError):
33323332
pass
33333333

3334-
def __getslice__(self, i, j):
3335-
"""
3336-
x.__getslice__(i, j) <==> x[i:j]
3337-
3338-
Return the slice described by (i, j). The use of negative indices
3339-
is not supported.
3340-
3341-
"""
3342-
return self.__getitem__(slice(i, j))
3343-
3344-
def __setslice__(self, i, j, value):
3345-
"""
3346-
x.__setslice__(i, j, value) <==> x[i:j]=value
3347-
3348-
Set the slice (i,j) of a to value. If value is masked, mask those
3349-
locations.
3350-
3351-
"""
3352-
self.__setitem__(slice(i, j), value)
3353-
33543334
def __setmask__(self, mask, copy=False):
33553335
"""
33563336
Set the mask.

‎numpy/ma/tests/test_extras.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ def test_single_non_masked_value_on_axis(self):
873873
def test_nan(self):
874874
with suppress_warnings() as w:
875875
w.record(RuntimeWarning)
876-
w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
877876
for mask in (False, np.zeros(6, dtype=np.bool)):
878877
dm = np.ma.array([[1, np.nan, 3], [1, 2, 3]])
879878
dm.mask = mask
@@ -923,7 +922,6 @@ def test_nan_behavior(self):
923922
a[2] = np.nan
924923
with suppress_warnings() as w:
925924
w.record(RuntimeWarning)
926-
w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
927925
assert_array_equal(np.ma.median(a), np.nan)
928926
assert_array_equal(np.ma.median(a, axis=0), np.nan)
929927
assert_(w.log[0].category is RuntimeWarning)
@@ -938,7 +936,6 @@ def test_nan_behavior(self):
938936
# no axis
939937
with suppress_warnings() as w:
940938
w.record(RuntimeWarning)
941-
w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
942939
warnings.filterwarnings('always', '', RuntimeWarning)
943940
assert_array_equal(np.ma.median(a), np.nan)
944941
assert_(np.isscalar(np.ma.median(a)))
@@ -1028,7 +1025,6 @@ def test_empty(self):
10281025
a = np.ma.masked_array(np.array([], dtype=float))
10291026
with suppress_warnings() as w:
10301027
w.record(RuntimeWarning)
1031-
w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
10321028
assert_array_equal(np.ma.median(a), np.nan)
10331029
assert_(w.log[0].category is RuntimeWarning)
10341030

@@ -1037,7 +1033,6 @@ def test_empty(self):
10371033
# no axis
10381034
with suppress_warnings() as w:
10391035
w.record(RuntimeWarning)
1040-
w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
10411036
warnings.filterwarnings('always', '', RuntimeWarning)
10421037
assert_array_equal(np.ma.median(a), np.nan)
10431038
assert_(w.log[0].category is RuntimeWarning)

‎numpy/testing/nosetester.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,6 @@ def test(self, label='fast', verbose=1, extra_argv=None,
420420
sup.filter(DeprecationWarning,
421421
r"sys\.exc_clear\(\) not supported in 3\.x",
422422
module=threading)
423-
sup.filter(DeprecationWarning, message=r"in 3\.x, __setslice__")
424-
sup.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
425423
sup.filter(DeprecationWarning, message=r"buffer\(\) not supported in 3\.x")
426424
sup.filter(DeprecationWarning, message=r"CObject type is not supported in 3\.x")
427425
sup.filter(DeprecationWarning, message=r"comparing unequal types not supported in 3\.x")

0 commit comments

Comments
 (0)