# Buggy code
def _broadcast_indexes(self, key):
    """Prepare an indexing key for an indexing operation.

    Parameters
    -----------
    key: int, slice, array, dict or tuple of integer, slices and arrays
        Any valid input for indexing.

    Returns
    -------
    dims: tuple
        Dimension of the resultant variable.
    indexers: IndexingTuple subclass
        Tuple of integer, array-like, or slices to use when indexing
        self._data. The type of this argument indicates the type of
        indexing to perform, either basic, outer or vectorized.
    new_order : Optional[Sequence[int]]
        Optional reordering to do on the result of indexing. If not None,
        the first len(new_order) indexing should be moved to these
        positions.
    """
    key = self._item_key_to_tuple(key)  # key is a tuple
    # key is a tuple of full size
    key = indexing.expanded_indexer(key, self.ndim)
    # Convert a scalar Variable as an integer
    key = tuple(
        [(k.data.item() if isinstance(k, Variable) and k.ndim == 0 else k) for k in key]
    )
    if all(isinstance(k, BASIC_INDEXING_TYPES) for k in key):
        return self._broadcast_indexes_basic(key)

    self._validate_indexers(key)
    # Detect it can be mapped as an outer indexer
    # If all key is unlabeled, or
    # key can be mapped as an OuterIndexer.
    if all(not isinstance(k, Variable) for k in key):
        return self._broadcast_indexes_outer(key)

    # If all key is 1-dimensional and there are no duplicate labels,
    # key can be mapped as an OuterIndexer.
    dims = []
    for k, d in zip(key, self.dims):
        if isinstance(k, Variable):
            if len(k.dims) > 1:
                return self._broadcast_indexes_vectorized(key)
            dims.append(k.dims[0])
        if not isinstance(k, integer_types):
            dims.append(d)

    if len(set(dims)) == len(dims):
        return self._broadcast_indexes_outer(key)

    return self._broadcast_indexes_vectorized(key)


# Traceback (ValueError)
import numpy as np
import xarray as xr

a = np.random.randn(4, 3)
a[1, 1] = np.NaN
da = xr.DataArray(a, dims=('y', 'x'), coords={'y':np.arange(4), 'x':np.arange(3)})
da.to_netcdf('test.nc')

with xr.open_dataarray('test.nc') as da:
da.dropna(dim='x', how='any')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-37-8d137cf3a813> in <module>()
8
9 with xr.open_dataarray('test.nc') as da:
---> 10     da.dropna(dim='x', how='any')

~/.pyvirtualenvs/py3/lib/python3.5/site-packages/xarray/core/dataarray.py in dropna(self, dim, how, thresh)
1158         DataArray
1159         """
-> 1160         ds = self._to_temp_dataset().dropna(dim, how=how, thresh=thresh)
1161         return self._from_temp_dataset(ds)
1162

~/.pyvirtualenvs/py3/lib/python3.5/site-packages/xarray/core/dataset.py in dropna(self, dim, how, thresh, subset)
2292             raise TypeError('must specify how or thresh')
2293
-> 2294         return self.isel(**{dim: mask})
2295
2296     def fillna(self, value):

~/.pyvirtualenvs/py3/lib/python3.5/site-packages/xarray/core/dataset.py in isel(self, drop, **indexers)
1291         coord_names = set(variables).intersection(self._coord_names)
1292         selected = self._replace_vars_and_dims(variables,
-> 1293                                                coord_names=coord_names)
1294
1295         # Extract coordinates from indexers

~/.pyvirtualenvs/py3/lib/python3.5/site-packages/xarray/core/dataset.py in _replace_vars_and_dims(self, variables, coord_names, dims, attrs, inplace)
598         """
599         if dims is None:
--> 600             dims = calculate_dimensions(variables)
601         if inplace:
602             self._dims = dims

~/.pyvirtualenvs/py3/lib/python3.5/site-packages/xarray/core/dataset.py in calculate_dimensions(variables)
111                 raise ValueError('conflicting sizes for dimension %r: '
112                                  'length %s on %r and length %s on %r' %
--> 113                                  (dim, size, k, dims[dim], last_used[dim]))
114     return dims
115

ValueError: conflicting sizes for dimension 'y': length 2 on <this-array> and length 4 on 'y'

# Fixed code
def _broadcast_indexes(self, key):
    """Prepare an indexing key for an indexing operation.

    Parameters
    -----------
    key: int, slice, array, dict or tuple of integer, slices and arrays
        Any valid input for indexing.

    Returns
    -------
    dims: tuple
        Dimension of the resultant variable.
    indexers: IndexingTuple subclass
        Tuple of integer, array-like, or slices to use when indexing
        self._data. The type of this argument indicates the type of
        indexing to perform, either basic, outer or vectorized.
    new_order : Optional[Sequence[int]]
        Optional reordering to do on the result of indexing. If not None,
        the first len(new_order) indexing should be moved to these
        positions.
    """
    key = self._item_key_to_tuple(key)  # key is a tuple
    # key is a tuple of full size
    key = indexing.expanded_indexer(key, self.ndim)
    # Convert a scalar Variable as an integer
    key = tuple(
        [(k.data.item() if isinstance(k, Variable) and k.ndim == 0 else k) for k in key]
    )
    if all(isinstance(k, BASIC_INDEXING_TYPES) for k in key):
        return self._broadcast_indexes_basic(key)

    self._validate_indexers(key)
    # Detect it can be mapped as an outer indexer
    # If all key is unlabeled, or
    # key can be mapped as an OuterIndexer.
    if all(not isinstance(k, Variable) for k in key):
        return self._broadcast_indexes_outer(key)

    # If all key is 1-dimensional and there are no duplicate labels,
    # key can be mapped as an OuterIndexer.
    dims = []
    for k, d in zip(key, self.dims):
        if isinstance(k, Variable):
            if len(k.dims) > 1:
                return self._broadcast_indexes_vectorized(key)
            dims.append(k.dims[0])
        elif not isinstance(k, integer_types):
            dims.append(d)
    if len(set(dims)) == len(dims):
        return self._broadcast_indexes_outer(key)

    return self._broadcast_indexes_vectorized(key)