# Buggy code
def get_index(self, key):
    """Get an index for a dimension, with fall-back to a default RangeIndex"""
    if key not in self.dims:
        raise KeyError(key)

    try:
        return self.indexes[key]
    except KeyError:
        return pd.Index(range(self.sizes[key]), name=key)


# Traceback (ValueError)
In [1]: import xarray as xr

In [2]: import numpy as np

In [3]: da = xr.DataArray(np.random.rand(100,10), dims=['nCells','nVertLevels'])

In [4]: mask = xr.DataArray(np.zeros((100,), dtype='bool'), dims='nCells')

In [5]: da.where(mask, drop=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-ca5cd9c083a9> in <module>()
----> 1 da.where(mask, drop=True)

/Users/pwolfram/src/xarray/xarray/core/common.pyc in where(self, cond, other, drop)
681             outcond = cond.isel(**clip)
682             indexers = {dim: outcond.get_index(dim) for dim in outcond.dims}
--> 683             outobj = self.sel(**indexers)
684         else:
685             outobj = self

/Users/pwolfram/src/xarray/xarray/core/dataarray.pyc in sel(self, method, tolerance, drop, **indexers)
670             self, indexers, method=method, tolerance=tolerance
671         )
--> 672         result = self.isel(drop=drop, **pos_indexers)
673         return result._replace_indexes(new_indexes)
674

/Users/pwolfram/src/xarray/xarray/core/dataarray.pyc in isel(self, drop, **indexers)
655         DataArray.sel
656         """
--> 657         ds = self._to_temp_dataset().isel(drop=drop, **indexers)
658         return self._from_temp_dataset(ds)
659

/Users/pwolfram/src/xarray/xarray/core/dataset.pyc in isel(self, drop, **indexers)
1115         for name, var in iteritems(self._variables):
1116             var_indexers = dict((k, v) for k, v in indexers if k in var.dims)
-> 1117             new_var = var.isel(**var_indexers)
1118             if not (drop and name in var_indexers):
1119                 variables[name] = new_var

/Users/pwolfram/src/xarray/xarray/core/variable.pyc in isel(self, **indexers)
545             if dim in indexers:
546                 key[i] = indexers[dim]
--> 547         return self[tuple(key)]
548
549     def squeeze(self, dim=None):

/Users/pwolfram/src/xarray/xarray/core/variable.pyc in __getitem__(self, key)
375         dims = tuple(dim for k, dim in zip(key, self.dims)
376                      if not isinstance(k, (int, np.integer)))
--> 377         values = self._indexable_data[key]
378         # orthogonal indexing should ensure the dimensionality is consistent
379         if hasattr(values, 'ndim'):

/Users/pwolfram/src/xarray/xarray/core/indexing.pyc in __getitem__(self, key)
465
466     def __getitem__(self, key):
--> 467         key = self._convert_key(key)
468         return self._ensure_ndarray(self.array[key])
469

/Users/pwolfram/src/xarray/xarray/core/indexing.pyc in _convert_key(self, key)
452         if any(not isinstance(k, (int, np.integer, slice)) for k in key):
453             # key would trigger fancy indexing
--> 454             key = orthogonal_indexer(key, self.shape)
455         return key
456

/Users/pwolfram/src/xarray/xarray/core/indexing.pyc in orthogonal_indexer(key, shape)
77     """
78     # replace Ellipsis objects with slices
---> 79     key = list(canonicalize_indexer(key, len(shape)))
80     # replace 1d arrays and slices with broadcast compatible arrays
81     # note: we treat integers separately (instead of turning them into 1d

/Users/pwolfram/src/xarray/xarray/core/indexing.pyc in canonicalize_indexer(key, ndim)
65         return indexer
66
---> 67     return tuple(canonicalize(k) for k in expanded_indexer(key, ndim))
68
69

/Users/pwolfram/src/xarray/xarray/core/indexing.pyc in <genexpr>((k,))
65         return indexer
66
---> 67     return tuple(canonicalize(k) for k in expanded_indexer(key, ndim))
68
69

/Users/pwolfram/src/xarray/xarray/core/indexing.pyc in canonicalize(indexer)
62                                      'array indexing; all subkeys must be '
63                                      'slices, integers or sequences of '
---> 64                                      'integers or Booleans' % indexer)
65         return indexer
66

ValueError: invalid subkey array([], dtype=object) for integer based array indexing; all subkeys must be slices, integers or sequences of integers or Booleans

# Fixed code
def get_index(self, key):
    """Get an index for a dimension, with fall-back to a default RangeIndex"""
    if key not in self.dims:
        raise KeyError(key)

    try:
        return self.indexes[key]
    except KeyError:
        # need to ensure dtype=int64 in case range is empty on Python 2
        return pd.Index(range(self.sizes[key]), name=key, dtype=np.int64)