summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-02-10 10:52:07 -0700
committerGitHub <noreply@github.com>2017-02-10 10:52:07 -0700
commit1b877254af0850d025cdc5d07b3fcaa1614dbe4b (patch)
tree8c16bd152cf3328515bd9502c19b0ca369d12d45 /numpy
parentb52be49a702862a44f18237c5a9a6c7f5173ddab (diff)
parent5e3fb00b37f5b1c752f6f44c5717b2d84ee7daff (diff)
downloadnumpy-1b877254af0850d025cdc5d07b3fcaa1614dbe4b.tar.gz
Merge pull request #8592 from eric-wieser/remove-setslice
MAINT: Remove __setslice__ and __getslice__
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/nditer_pywrap.c4
-rw-r--r--numpy/core/src/multiarray/sequence.c90
-rw-r--r--numpy/lib/index_tricks.py7
-rw-r--r--numpy/lib/user_array.py6
-rw-r--r--numpy/ma/core.py20
-rw-r--r--numpy/ma/tests/test_extras.py5
-rw-r--r--numpy/testing/nosetester.py2
7 files changed, 5 insertions, 129 deletions
diff --git a/numpy/core/src/multiarray/nditer_pywrap.c b/numpy/core/src/multiarray/nditer_pywrap.c
index c735e7ad1..3d035390c 100644
--- a/numpy/core/src/multiarray/nditer_pywrap.c
+++ b/numpy/core/src/multiarray/nditer_pywrap.c
@@ -2416,9 +2416,9 @@ NPY_NO_EXPORT PySequenceMethods npyiter_as_sequence = {
(binaryfunc)NULL, /*sq_concat*/
(ssizeargfunc)NULL, /*sq_repeat*/
(ssizeargfunc)npyiter_seq_item, /*sq_item*/
- (ssizessizeargfunc)npyiter_seq_slice, /*sq_slice*/
+ (ssizessizeargfunc)NULL, /*sq_slice*/
(ssizeobjargproc)npyiter_seq_ass_item, /*sq_ass_item*/
- (ssizessizeobjargproc)npyiter_seq_ass_slice,/*sq_ass_slice*/
+ (ssizessizeobjargproc)NULL, /*sq_ass_slice*/
(objobjproc)NULL, /*sq_contains */
(binaryfunc)NULL, /*sq_inplace_concat */
(ssizeargfunc)NULL, /*sq_inplace_repeat */
diff --git a/numpy/core/src/multiarray/sequence.c b/numpy/core/src/multiarray/sequence.c
index 520732acf..55b72c198 100644
--- a/numpy/core/src/multiarray/sequence.c
+++ b/numpy/core/src/multiarray/sequence.c
@@ -27,90 +27,6 @@ array_any_nonzero(PyArrayObject *mp);
we fill it in here so that PySequence_XXXX calls work as expected
*/
-
-static PyObject *
-array_slice(PyArrayObject *self, Py_ssize_t ilow, Py_ssize_t ihigh)
-{
- PyArrayObject *ret;
- PyArray_Descr *dtype;
- Py_ssize_t dim0;
- char *data;
- npy_intp shape[NPY_MAXDIMS];
-
- if (PyArray_NDIM(self) == 0) {
- PyErr_SetString(PyExc_ValueError, "cannot slice a 0-d array");
- return NULL;
- }
-
- dim0 = PyArray_DIM(self, 0);
- if (ilow < 0) {
- ilow = 0;
- }
- else if (ilow > dim0) {
- ilow = dim0;
- }
- if (ihigh < ilow) {
- ihigh = ilow;
- }
- else if (ihigh > dim0) {
- ihigh = dim0;
- }
-
- data = PyArray_DATA(self);
- if (ilow < ihigh) {
- data += ilow * PyArray_STRIDE(self, 0);
- }
-
- /* Same shape except dimension 0 */
- shape[0] = ihigh - ilow;
- memcpy(shape+1, PyArray_DIMS(self) + 1,
- (PyArray_NDIM(self)-1)*sizeof(npy_intp));
-
- dtype = PyArray_DESCR(self);
- Py_INCREF(dtype);
- ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(self), dtype,
- PyArray_NDIM(self), shape,
- PyArray_STRIDES(self), data,
- PyArray_FLAGS(self),
- (PyObject *)self);
- if (ret == NULL) {
- return NULL;
- }
- Py_INCREF(self);
- if (PyArray_SetBaseObject(ret, (PyObject *)self) < 0) {
- Py_DECREF(ret);
- return NULL;
- }
- PyArray_UpdateFlags(ret, NPY_ARRAY_UPDATE_ALL);
-
- return (PyObject *)ret;
-}
-
-
-static int
-array_assign_slice(PyArrayObject *self, Py_ssize_t ilow,
- Py_ssize_t ihigh, PyObject *v) {
- int ret;
- PyArrayObject *tmp;
-
- if (v == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "cannot delete array elements");
- return -1;
- }
- if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) {
- return -1;
- }
- tmp = (PyArrayObject *)array_slice(self, ilow, ihigh);
- if (tmp == NULL) {
- return -1;
- }
- ret = PyArray_CopyObject(tmp, v);
- Py_DECREF(tmp);
-
- return ret;
-}
-
static int
array_contains(PyArrayObject *self, PyObject *el)
{
@@ -134,9 +50,9 @@ NPY_NO_EXPORT PySequenceMethods array_as_sequence = {
(binaryfunc)NULL, /*sq_concat is handled by nb_add*/
(ssizeargfunc)NULL,
(ssizeargfunc)array_item,
- (ssizessizeargfunc)array_slice,
- (ssizeobjargproc)array_assign_item, /*sq_ass_item*/
- (ssizessizeobjargproc)array_assign_slice, /*sq_ass_slice*/
+ (ssizessizeargfunc)NULL,
+ (ssizeobjargproc)array_assign_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)NULL, /*sq_ass_slice*/
(objobjproc) array_contains, /*sq_contains */
(binaryfunc) NULL, /*sg_inplace_concat */
(ssizeargfunc)NULL,
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index a0875a25f..f573cd4c6 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -209,9 +209,6 @@ class nd_grid(object):
else:
return _nx.arange(start, stop, step)
- def __getslice__(self, i, j):
- return _nx.arange(i, j)
-
def __len__(self):
return 0
@@ -338,10 +335,6 @@ class AxisConcatenator(object):
res = _nx.concatenate(tuple(objs), axis=self.axis)
return self._retval(res)
- def __getslice__(self, i, j):
- res = _nx.arange(i, j)
- return self._retval(res)
-
def __len__(self):
return 0
diff --git a/numpy/lib/user_array.py b/numpy/lib/user_array.py
index 3103da57b..62398fc3c 100644
--- a/numpy/lib/user_array.py
+++ b/numpy/lib/user_array.py
@@ -51,15 +51,9 @@ class container(object):
def __getitem__(self, index):
return self._rc(self.array[index])
- def __getslice__(self, i, j):
- return self._rc(self.array[i:j])
-
def __setitem__(self, index, value):
self.array[index] = asarray(value, self.dtype)
- def __setslice__(self, i, j, value):
- self.array[i:j] = asarray(value, self.dtype)
-
def __abs__(self):
return self._rc(absolute(self.array))
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 69c401e01..a46a6f50c 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3331,26 +3331,6 @@ class MaskedArray(ndarray):
except (AttributeError, TypeError):
pass
- def __getslice__(self, i, j):
- """
- x.__getslice__(i, j) <==> x[i:j]
-
- Return the slice described by (i, j). The use of negative indices
- is not supported.
-
- """
- return self.__getitem__(slice(i, j))
-
- def __setslice__(self, i, j, value):
- """
- x.__setslice__(i, j, value) <==> x[i:j]=value
-
- Set the slice (i,j) of a to value. If value is masked, mask those
- locations.
-
- """
- self.__setitem__(slice(i, j), value)
-
def __setmask__(self, mask, copy=False):
"""
Set the mask.
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 58ac46f53..fb68bd261 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -873,7 +873,6 @@ class TestMedian(TestCase):
def test_nan(self):
with suppress_warnings() as w:
w.record(RuntimeWarning)
- w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
for mask in (False, np.zeros(6, dtype=np.bool)):
dm = np.ma.array([[1, np.nan, 3], [1, 2, 3]])
dm.mask = mask
@@ -923,7 +922,6 @@ class TestMedian(TestCase):
a[2] = np.nan
with suppress_warnings() as w:
w.record(RuntimeWarning)
- w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
assert_array_equal(np.ma.median(a), np.nan)
assert_array_equal(np.ma.median(a, axis=0), np.nan)
assert_(w.log[0].category is RuntimeWarning)
@@ -938,7 +936,6 @@ class TestMedian(TestCase):
# no axis
with suppress_warnings() as w:
w.record(RuntimeWarning)
- w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
warnings.filterwarnings('always', '', RuntimeWarning)
assert_array_equal(np.ma.median(a), np.nan)
assert_(np.isscalar(np.ma.median(a)))
@@ -1028,7 +1025,6 @@ class TestMedian(TestCase):
a = np.ma.masked_array(np.array([], dtype=float))
with suppress_warnings() as w:
w.record(RuntimeWarning)
- w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
assert_array_equal(np.ma.median(a), np.nan)
assert_(w.log[0].category is RuntimeWarning)
@@ -1037,7 +1033,6 @@ class TestMedian(TestCase):
# no axis
with suppress_warnings() as w:
w.record(RuntimeWarning)
- w.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
warnings.filterwarnings('always', '', RuntimeWarning)
assert_array_equal(np.ma.median(a), np.nan)
assert_(w.log[0].category is RuntimeWarning)
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py
index 3d9616ed8..da5d112f5 100644
--- a/numpy/testing/nosetester.py
+++ b/numpy/testing/nosetester.py
@@ -420,8 +420,6 @@ class NoseTester(object):
sup.filter(DeprecationWarning,
r"sys\.exc_clear\(\) not supported in 3\.x",
module=threading)
- sup.filter(DeprecationWarning, message=r"in 3\.x, __setslice__")
- sup.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
sup.filter(DeprecationWarning, message=r"buffer\(\) not supported in 3\.x")
sup.filter(DeprecationWarning, message=r"CObject type is not supported in 3\.x")
sup.filter(DeprecationWarning, message=r"comparing unequal types not supported in 3\.x")