Skip to content
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

Added more descriptive error message if indexing with all False bool … #1197

Closed
wants to merge 7 commits into from
6 changes: 6 additions & 0 deletions src/netCDF4/utils.py
Expand Up @@ -208,6 +208,12 @@ def _StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None,\
if sum(1 for e in elem if e is Ellipsis) > 1:
raise IndexError("At most one ellipsis allowed in a slicing expression")

# Check if elem is valid for bool array.
if type(elem) is np.ndarray:
if elem.dtype is np.dtype(bool) and np.logical_not(np.any(elem))
raise IndexError("All elements of bool indexing array are False. "
"At least one element must be True to be valid.")

# replace boolean arrays with sequences of integers.
newElem = []
IndexErrorMsg=\
Expand Down