8000 MAINT: Remove python2 array_{get,set}slice by sethtroisi · Pull Request #15263 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Remove python2 array_{get,set}slice #15263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions numpy/_pytesttester.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ def __call__(self, label='fast', verbose=1, extra_argv=None,

# 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",
Expand Down
62 changes: 0 additions & 62 deletions numpy/core/src/multiarray/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -2749,23 +2704,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,
Expand Down
34 changes: 0 additions & 34 deletions numpy/core/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,40 +648,6 @@ def __array_finalize__(self, old):
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):
Expand Down
2 changes: 0 additions & 2 deletions numpy/testing/_private/nosetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ def test(self, label='fast', verbose=1, extra_argv=None,
# 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")
Expand Down
2 changes: 0 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ filterwarnings =
# Matrix PendingDeprecationWarning.
ignore:the matrix subclass is not
# Ignore python2.7 -3 warnings
ignore:in 3\.x, __setslice__:DeprecationWarning
ignore:in 3\.x, __getslice__:DeprecationWarning
ignore:buffer\(\) not supported in 3\.x:DeprecationWarning
ignore:CObject type is not supported in 3\.x:DeprecationWarning
ignore:comparing unequal types not supported in 3\.x:DeprecationWarning
Expand Down
0