summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-07 02:44:45 -0800
committerEric Wieser <wieser.eric@gmail.com>2020-01-07 10:44:45 +0000
commitebd2def8783aedf4417135c09246b7cc26136f69 (patch)
tree8502e5d6985115fa397f72e026558064c79a9abc /numpy
parent6f26c12cf0377b926f43f827bd1291a941875751 (diff)
downloadnumpy-ebd2def8783aedf4417135c09246b7cc26136f69.tar.gz
MAINT: Remove python2 array_getslice and array_setslice (#15263)
These implemented the __getslice__ and __setslice__ methods in Python 2, which no longer exist in Python 3.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/_pytesttester.py2
-rw-r--r--numpy/core/src/multiarray/methods.c62
-rw-r--r--numpy/core/tests/test_indexing.py34
-rw-r--r--numpy/testing/_private/nosetester.py2
4 files changed, 0 insertions, 100 deletions
diff --git a/numpy/_pytesttester.py b/numpy/_pytesttester.py
index 56eb3ac67..8b6e3217e 100644
--- a/numpy/_pytesttester.py
+++ b/numpy/_pytesttester.py
@@ -164,8 +164,6 @@ class PytestTester:
# Ignore python2.7 -3 warnings
pytest_args += [
- r"-W ignore:in 3\.x, __setslice__:DeprecationWarning",
- r"-W ignore:in 3\.x, __getslice__:DeprecationWarning",
r"-W ignore:buffer\(\) not supported in 3\.x:DeprecationWarning",
r"-W ignore:CObject type is not supported in 3\.x:DeprecationWarning",
r"-W ignore:comparing unequal types not supported in 3\.x:DeprecationWarning",
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index 3b6e37ac8..55c74eeb2 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -2641,51 +2641,6 @@ array_complex(PyArrayObject *self, PyObject *NPY_UNUSED(args))
return c;
}
-#ifndef NPY_PY3K
-
-static PyObject *
-array_getslice(PyArrayObject *self, PyObject *args)
-{
- PyObject *start, *stop, *slice, *result;
- if (!PyArg_ParseTuple(args, "OO:__getslice__", &start, &stop)) {
- return NULL;
- }
-
- slice = PySlice_New(start, stop, NULL);
- if (slice == NULL) {
- return NULL;
- }
-
- /* Deliberately delegate to subclasses */
- result = PyObject_GetItem((PyObject *)self, slice);
- Py_DECREF(slice);
- return result;
-}
-
-static PyObject *
-array_setslice(PyArrayObject *self, PyObject *args)
-{
- PyObject *start, *stop, *value, *slice;
- if (!PyArg_ParseTuple(args, "OOO:__setslice__", &start, &stop, &value)) {
- return NULL;
- }
-
- slice = PySlice_New(start, stop, NULL);
- if (slice == NULL) {
- return NULL;
- }
-
- /* Deliberately delegate to subclasses */
- if (PyObject_SetItem((PyObject *)self, slice, value) < 0) {
- Py_DECREF(slice);
- return NULL;
- }
- Py_DECREF(slice);
- Py_RETURN_NONE;
-}
-
-#endif
-
NPY_NO_EXPORT PyMethodDef array_methods[] = {
/* for subtypes */
@@ -2743,23 +2698,6 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
(PyCFunction) array_format,
METH_VARARGS, NULL},
-#ifndef NPY_PY3K
- /*
- * While we could put these in `tp_sequence`, its' easier to define them
- * in terms of PyObject* arguments.
- *
- * We must provide these for compatibility with code that calls them
- * directly. They are already deprecated at a language level in python 2.7,
- * but are removed outright in python 3.
- */
- {"__getslice__",
- (PyCFunction) array_getslice,
- METH_VARARGS, NULL},
- {"__setslice__",
- (PyCFunction) array_setslice,
- METH_VARARGS, NULL},
-#endif
-
/* Original and Extended methods added 2005 */
{"all",
(PyCFunction)array_all,
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 56bcf0177..237e381a7 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -648,40 +648,6 @@ class TestSubclasses:
assert_array_equal(new_s.finalize_status, new_s)
assert_array_equal(new_s.old, s)
- @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
- def test_slice_decref_getsetslice(self):
- # See gh-10066, a temporary slice object should be discarted.
- # This test is only really interesting on Python 2 since
- # it goes through `__set/getslice__` here and can probably be
- # removed. Use 0:7 to make sure it is never None:7.
- class KeepIndexObject(np.ndarray):
- def __getitem__(self, indx):
- self.indx = indx
- if indx == slice(0, 7):
- raise ValueError
-
- def __setitem__(self, indx, val):
- self.indx = indx
- if indx == slice(0, 4):
- raise ValueError
-
- k = np.array([1]).view(KeepIndexObject)
- k[0:5]
- assert_equal(k.indx, slice(0, 5))
- assert_equal(sys.getrefcount(k.indx), 2)
- with assert_raises(ValueError):
- k[0:7]
- assert_equal(k.indx, slice(0, 7))
- assert_equal(sys.getrefcount(k.indx), 2)
-
- k[0:3] = 6
- assert_equal(k.indx, slice(0, 3))
- assert_equal(sys.getrefcount(k.indx), 2)
- with assert_raises(ValueError):
- k[0:4] = 2
- assert_equal(k.indx, slice(0, 4))
- assert_equal(sys.getrefcount(k.indx), 2)
-
class TestFancyIndexingCast:
def test_boolean_index_cast_assign(self):
diff --git a/numpy/testing/_private/nosetester.py b/numpy/testing/_private/nosetester.py
index 73f5b3d35..4ca5267ce 100644
--- a/numpy/testing/_private/nosetester.py
+++ b/numpy/testing/_private/nosetester.py
@@ -454,8 +454,6 @@ class NoseTester:
# This is very specific, so using the fragile module filter
# is fine
import 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")