diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2020-08-06 17:20:24 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-06 18:20:24 -0500 |
commit | 29e2293844e0ac2772b1382ab0ec6a35543954de (patch) | |
tree | 9c2ad06f6890fb3115d7e0c37c3e247185770502 /doc/release | |
parent | 3023d06a05136bf8345e781cc11a01d776a9f314 (diff) | |
download | numpy-29e2293844e0ac2772b1382ab0ec6a35543954de.tar.gz |
BUG: Raise correct errors in boolean indexing fast path (gh-17010)
Previously the logic assumed that an index was valid if the size was the same
as the indexed array, rather than the shape. This resulted in an index being
incorrectly allowed if the index was all False, like np.empty((3, 3))[np.full((1, 9),
False)], or incorrectly giving a ValueError about broadcasting if the index
was not all False (like np.empty((3, 3))[np.full((1, 9), True)]). Now these
examples both give IndexError with the usual error message.
Fixes #16997.
Diffstat (limited to 'doc/release')
-rw-r--r-- | doc/release/upcoming_changes/17010.compatibility.rst | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/release/upcoming_changes/17010.compatibility.rst b/doc/release/upcoming_changes/17010.compatibility.rst new file mode 100644 index 000000000..72ca0a963 --- /dev/null +++ b/doc/release/upcoming_changes/17010.compatibility.rst @@ -0,0 +1,24 @@ +Boolean array indices with mismatching shapes now properly give ``IndexError`` +------------------------------------------------------------------------------ + +Previously, if a boolean array index matched the size of the indexed array but +not the shape, it was incorrectly allowed in some cases. In other cases, it +gave an error, but the error was incorrectly a ``ValueError`` with a message +about broadcasting instead of the correct ``IndexError``. + +For example, the following used to incorrectly give ``ValueError: operands +could not be broadcast together with shapes (2,2) (1,4)``: + +.. code:: python + + np.empty((2, 2))[np.array([[True, False, False, False]])] + +And the following used to incorrectly return ``array([], dtype=float64)``: + +.. code:: python + + np.empty((2, 2))[np.array([[False, False, False, False]])] + +Both now correctly give ``IndexError: boolean index did not match indexed +array along dimension 0; dimension is 2 but corresponding boolean dimension is +1``. |