-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: Handle expired deprecations. #8297
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
Conversation
These changes have been warned of since numpy 1.7.0 for the == case and since numpy 1.8 for the != case. This makes both operators compare element-wise for this case.
Non-integer index has been deprecated since NumPy 1.8.0.
NpyIter_AdvancedNew raises ValueError when `oa_ndim == 0` and `op_axes` is NULL. Deprecated since NumPy 1.8.
The unary minus of booleans was deprecated in NumPy 1.9.
Subtracting a bool_ from a bool_ was deprecated in NumPy 1.9
4a46daf
to
c9adc35
Compare
This only applies to object arrays. Previously object identity would override object comparison failures, comparison of objects that did not return a boolean (arrays), and comparison of objects where the comparison result did not agree with the object identity result (NaNs) The first two behaviors have been deprecated since 1.9 and now return errors. The last has issued a FutureWarning since 1.9 and now returns the result of the comparison.
@seberg I'm dealing with all the boolean indexing deprecations and I have found the following odd behavior:
So scalar indexing adds a dimension. What is the logic there? I also find it strange that True and False lead to the same results. |
Hmmm, that is a bug then :(. It should be |
Did not test, but try to chang line 464 |
#assert_equal(a[np.array(False), a[None][0:0]]) | ||
assert_equal(a[np.array(True)], a[None]) | ||
# @seberg, should this work? | ||
# assert_equal(a[np.array(False), a[None][0:0]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seberg This was a failing test that caught that wrong behavior for False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ummm, the test has the squared brackets set wrong, but other then that, yes it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this seems to do the trick:
@@ -441,16 +441,6 @@ prepare_index(PyArrayObject *self, PyObject *index,
if (PyArray_NDIM(arr) == 0) {
/*
- * TODO, WARNING: This code block cannot be used due to
- * FutureWarnings at this time. So instead
- * just raise an IndexError.
- */
- PyErr_SetString(PyExc_IndexError,
- "in the future, 0-d boolean arrays will be "
- "interpreted as a valid boolean index");
- Py_DECREF((PyObject *)arr);
- goto failed_building_indices;
- /*
* This can actually be well defined. A new axis is added,
* but at the same time no axis is "used". So if we have True,
* we add a new axis (a bit like with np.newaxis). If it is
@@ -459,7 +449,6 @@ prepare_index(PyArrayObject *self, PyObject *index,
index_type |= HAS_FANCY;
indices[curr_idx].type = HAS_0D_BOOL;
- indices[curr_idx].value = 1;
/* TODO: This can't fail, right? Is there a faster way? */
if (PyObject_IsTrue((PyObject *)arr)) {
@@ -468,6 +457,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
else {
n = 0;
}
+ indices[curr_idx].value = n;
indices[curr_idx].object = PyArray_Zeros(1, &n,
PyArray_DescrFromType(NPY_INTP), 0);
Py_DECREF(arr);
@@ -2450,6 +2440,10 @@ mapiter_fill_info(PyArrayMapIterObject *mit, npy_index_info *indices,
mit->fancy_dims[j] = 1;
/* Does not exist */
mit->iteraxes[j++] = -1;
+ if (mit->dimensions[mit->nd_fancy-1] > 1) {
+ goto broadcast_error;
+ }
+ mit->dimensions[mit->nd_fancy-1] *= indices[i].value;
}
/* advance curr_dim for non-fancy indices */
@@ -2487,7 +2481,7 @@ mapiter_fill_info(PyArrayMapIterObject *mit, npy_index_info *indices,
}
for (i = 0; i < index_num; i++) {
- if (indices[i].type != HAS_FANCY) {
+ if (!(indices[i].type & HAS_FANCY)) {
continue;
}
tmp = convert_shape_to_string(
I still suggest to split it off, it likely warrents more new tests, and another look.
Nope, that doesn't solve the problem... |
:( I will have to check myself more closely I guess. |
Seems to work except for that bit. I'm tempted to put in the other deprecation updates and put this one off until it gets working. |
Yeah. Split it off for now. That one might be a bit more hassle even after finding out that bug. |
8259082
to
f562e5b
Compare
I moved the index stuff to #8312. |
The move seems to have removed your last comment. |
Copied from post from @seberg. OK, this seems to do the trick: @@ -441,16 +441,6 @@ prepare_index(PyArrayObject *self, PyObject *index,
if (PyArray_NDIM(arr) == 0) {
/*
- * TODO, WARNING: This code block cannot be used due to
- * FutureWarnings at this time. So instead
- * just raise an IndexError.
- */
- PyErr_SetString(PyExc_IndexError,
- "in the future, 0-d boolean arrays will be "
- "interpreted as a valid boolean index");
- Py_DECREF((PyObject *)arr);
- goto failed_building_indices;
- /*
* This can actually be well defined. A new axis is added,
* but at the same time no axis is "used". So if we have True,
* we add a new axis (a bit like with np.newaxis). If it is
@@ -459,7 +449,6 @@ prepare_index(PyArrayObject *self, PyObject *index,
index_type |= HAS_FANCY;
indices[curr_idx].type = HAS_0D_BOOL;
- indices[curr_idx].value = 1;
/* TODO: This can't fail, right? Is there a faster way? */
if (PyObject_IsTrue((PyObject *)arr)) {
@@ -468,6 +457,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
else {
n = 0;
}
+ indices[curr_idx].value = n;
indices[curr_idx].object = PyArray_Zeros(1, &n,
PyArray_DescrFromType(NPY_INTP), 0);
Py_DECREF(arr);
@@ -2450,6 +2440,10 @@ mapiter_fill_info(PyArrayMapIterObject *mit, npy_index_info *indices,
mit->fancy_dims[j] = 1;
/* Does not exist */
mit->iteraxes[j++] = -1;
+ if (mit->dimensions[mit->nd_fancy-1] > 1) {
+ goto broadcast_error;
+ }
+ mit->dimensions[mit->nd_fancy-1] *= indices[i].value;
}
/* advance curr_dim for non-fancy indices */
@@ -2487,7 +2481,7 @@ mapiter_fill_info(PyArrayMapIterObject *mit, npy_index_info *indices,
}
for (i = 0; i < index_num; i++) {
- if (indices[i].type != HAS_FANCY) {
+ if (!(indices[i].type & HAS_FANCY)) {
continue;
}
tmp = convert_shape_to_string( |
@@ -1361,19 +1361,18 @@ def test_eq_with_None(self): | |||
# With partial mask | |||
with suppress_warnings() as sup: | |||
sup.filter(FutureWarning, "Comparison to `None`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it may not be now, could try removing it. Which reminds me that there are a lot of expired deprecations in 1.15 that we should deal with soon.
Changes
Deprecations to error
partition
, TypeError when non-integer partition index is used.NpyIter_AdvancedNew
, ValueError whenoa_ndim == 0
andop_axes
is NULLnegative(bool_)
, TypeError when negative applied to booleans.subtract(bool_, bool_)
, TypeError when subtracting boolean from boolean.np.equal, np.not_equal
, object identity doesn't override failed comparison.np.equal, np.not_equal
, object identity doesn't override non-boolean comparison.FutureWarnings to changed behavior
array == None
andarray != None
do element-wise comparison.np.equal, np.not_equal
, object identity doesn't override comparison result.