8000 MAINT: Remove python2 array_getslice and array_setslice (#15263) · numpy/numpy@ebd2def · GitHub
[go: up one dir, main page]

Skip to content

Commit ebd2def

Browse files
sethtroisieric-wieser
authored andcommitted
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.
1 parent 6f26c12 commit ebd2def

File tree

5 files changed

+0
-102
lines changed

5 files changed

+0
-102
lines changed

numpy/_pytesttester.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ def __call__(self, label='fast', verbose=1, extra_argv=None,
164164 8000

165165
# Ignore python2.7 -3 warnings
166166
pytest_args += [
167-
r"-W ignore:in 3\.x, __setslice__:DeprecationWarning",
168-
r"-W ignore:in 3\.x, __getslice__:DeprecationWarning",
169167
r"-W ignore:buffer\(\) not supported in 3\.x:DeprecationWarning",
170168
r"-W ignore:CObject type is not supported in 3\.x:DeprecationWarning",
171169
r"-W ignore:comparing unequal types not supported in 3\.x:DeprecationWarning",

numpy/core/src/multiarray/methods.c

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,51 +2641,6 @@ array_complex(PyArrayObject *self, PyObject *NPY_UNUSED(args))
26412641
return c;
26422642
}
26432643

2644-
#ifndef NPY_PY3K
2645-
2646-
static PyObject *
2647-
array_getslice(PyArrayObject *self, PyObject *args)
2648-
{
2649-
PyObject *start, *stop, *slice, *result;
2650-
if (!PyArg_ParseTuple(args, "OO:__getslice__", &start, &stop)) {
2651-
return NULL;
2652-
}
2653-
2654-
slice = PySlice_New(start, stop, NULL);
2655-
if (slice == NULL) {
2656-
return NULL;
2657-
}
2658-
2659-
/* Deliberately delegate to subclasses */
2660-
result = PyObject_GetItem((PyObject *)self, slice);
2661-
Py_DECREF(slice);
2662-
return result;
2663-
}
2664-
2665-
static PyObject *
2666-
array_setslice(PyArrayObject *self, PyObject *args)
2667-
{
2668-
PyObject *start, *stop, *value, *slice;
2669-
if (!PyArg_ParseTuple(args, "OOO:__setslice__", &start, &stop, &value)) {
2670-
return NULL;
2671-
}
2672-
2673-
slice = PySlice_New(start, stop, NULL);
2674-
if (slice == NULL) {
2675-
return NULL;
2676-
}
2677-
2678-
/* Deliberately delegate to subclasses */
2679-
if (PyObject_SetItem((PyObject *)self, slice, value) < 0) {
2680-
Py_DECREF(slice);
2681-
return NULL;
2682-
}
2683-
Py_DECREF(slice);
2684-
Py_RETURN_NONE;
2685-
}
2686-
2687-
#endif
2688-
26892644
NPY_NO_EXPORT PyMethodDef array_methods[] = {
26902645

26912646
/* for subtypes */
@@ -2743,23 +2698,6 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
27432698
(PyCFunction) array_format,
27442699
METH_VARARGS, NULL},
27452700

2746-
#ifndef NPY_PY3K
2747-
/*
2748-
* While we could put these in `tp_sequence`, its' easier to define them
2749-
* in terms of PyObject* arguments.
2750-
*
2751-
* We must provide these for compatibility with code that calls them
2752-
* directly. They are already deprecated at a language level in python 2.7,
2753-
* but are removed outright in python 3.
2754-
*/
2755-
{"__getslice__",
2756-
(PyCFunction) array_getslice,
2757-
METH_VARARGS, NULL},
2758-
{"__setslice__",
2759-
(PyCFunction) array_setslice,
2760-
METH_VARARGS, NULL},
2761-
#endif
2762-
27632701
/* Original and Extended methods added 2005 */
27642702
{"all",
27652703
(PyCFunction)array_all,

numpy/core/tests/test_indexing.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -648,40 +648,6 @@ def __array_finalize__(self, old):
648648
assert_array_equal(new_s.finalize_status, new_s)
649649
assert_array_equal(new_s.old, s)
650650

651-
@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
652-
def test_slice_decref_getsetslice(self):
653-
# See gh-10066, a temporary slice object should be discarted.
654-
# This test is only really interesting on Python 2 since
655-
# it goes through `__set/getslice__` here and can probably be
656-
# removed. Use 0:7 to make sure it is never None:7.
657-
class KeepIndexObject(np.ndarray):
658-
def __getitem__(self, indx):
659-
self.indx = indx
660-
if indx == slice(0, 7):
661-
raise ValueError
662-
663-
def __setitem__(self, indx, val):
664-
self.indx = indx
665-
if indx == slice(0, 4):
666-
raise ValueError
667-
668-
k = np.array([1]).view(KeepIndexObject)
669-
k[0:5]
670-
assert_equal(k.indx, slice(0, 5))
671-
assert_equal(sys.getrefcount(k.indx), 2)
672-
with assert_raises(ValueError):
673-
k[0:7]
674-
assert_equal(k.indx, slice(0, 7))
675-
assert_equal(sys.getrefcount(k.indx), 2)
676-
677-
k[0:3] = 6
678-
assert_equal(k.indx, slice(0, 3))
679-
assert_equal(sys.getrefcount(k.indx), 2)
680-
with assert_raises(ValueError):
681-
k[0:4] = 2
682-
assert_equal(k.indx, slice(0, 4))
683-
assert_equal(sys.getrefcount(k.indx), 2)
684-
685651

686652
class TestFancyIndexingCast:
687653
def test_boolean_index_cast_assign(self):

numpy/testing/_private/nosetester.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ def test(self, label='fast', verbose=1, extra_argv=None,
454454
# This is very specific, so using the fragile module filter
455455
# is fine
456456
import threading
457-
sup.filter(DeprecationWarning, message=r"in 3\.x, __setslice__")
458-
sup.filter(DeprecationWarning, message=r"in 3\.x, __getslice__")
459457
sup.filter(DeprecationWarning, message=r"buffer\(\) not supported in 3\.x")
460458
sup.filter(DeprecationWarning, message=r"CObject type is not supported in 3\.x")
461459
sup.filter(DeprecationWarning, message=r"comparing unequal types not supported in 3\.x")

pytest.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ filterwarnings =
1414
# Matrix PendingDeprecationWarning.
1515
ignore:the matrix subclass is not
1616
# Ignore python2.7 -3 warnings
17-
ignore:in 3\.x, __setslice__:DeprecationWarning
18-
ignore:in 3\.x, __getslice__:DeprecationWarning
1917
ignore:buffer\(\) not supported in 3\.x:DeprecationWarning
2018
ignore:CObject type is not supported in 3\.x:DeprecationWarning
2119
ignore:comparing unequal types not supported in 3\.x:DeprecationWarning

0 commit comments

Comments
 (0)
0