# Buggy code
def dropna(self, dim, how="any", thresh=None, subset=None):
    """Returns a new dataset with dropped labels for missing values along
    the provided dimension.

    Parameters
    ----------
    dim : str
        Dimension along which to drop missing values. Dropping along
        multiple dimensions simultaneously is not yet supported.
    how : {'any', 'all'}, optional
        * any : if any NA values are present, drop that label
        * all : if all values are NA, drop that label
    thresh : int, default None
        If supplied, require this many non-NA values.
    subset : sequence, optional
        Subset of variables to check for missing values. By default, all
        variables in the dataset are checked.

    Returns
    -------
    Dataset
    """
    # TODO: consider supporting multiple dimensions? Or not, given that
    # there are some ugly edge cases, e.g., pandas's dropna differs
    # depending on the order of the supplied axes.

    if dim not in self.dims:
        raise ValueError("%s must be a single dataset dimension" % dim)

    if subset is None:
        subset = list(self.data_vars)

    count = np.zeros(self.dims[dim], dtype=int)
    size = 0

    for k in subset:
        array = self._variables[k]
        if dim in array.dims:
            dims = [d for d in array.dims if d != dim]
            count += array.count(dims)
            size += np.prod([self.dims[d] for d in dims])

    if thresh is not None:
        mask = count >= thresh
    elif how == "any":
        mask = count == size
    elif how == "all":
        mask = count > 0
    elif how is not None:
        raise ValueError("invalid how option: %s" % how)
    else:
        raise TypeError("must specify how or thresh")

    return self.isel(**{dim: mask})


# Traceback (WindowsError)
$ nosetests xray

SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS..C:\Python27\Anaconda\lib\site-packages\scipy\io\netcdf.py:287: RuntimeWarning: Cannot close a netcdf_file opened with mmap=True, when netcdf_variables or arrays referring to its data still exist. All data arrays obtained from such files refer directly to data on disk, and must be copied before the file can be cleanly closed. (See netcdf_file docstring for more information on mmap.)
), category=RuntimeWarning)
.........C:\Python27\Anaconda\lib\site-packages\xray\core\utils.py:53: FutureWarning: numpy equal will not check object identity in the future. The comparison did not return the same result as suggested by the identity (`is`)) and will change.
return ((arr1 == arr2) | (pd.isnull(arr1) &amp; pd.isnull(arr2))).all()
.....EE.EE.E.EEE.E.EE.SSSSSSSSSSSSSSSS...S.SS.SSSSS.....SSS.............F...................S...................F....S......................F........................................S.............F............................F....................................................F.................................
======================================================================
ERROR: test_load_data (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 92, in test_load_data
pass
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 87, in assert_loads
self.assertDatasetAllClose(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpnniync.nc'

======================================================================
ERROR: test_orthogonal_indexing (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 211, in test_orthogonal_indexing
self.assertDatasetAllClose(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpanlrts.nc'

======================================================================
ERROR: test_roundtrip_None_variable (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 108, in test_roundtrip_None_variable
self.assertDatasetAllClose(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpinhb9v.nc'

======================================================================
ERROR: test_roundtrip_coordinates (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 182, in test_roundtrip_coordinates
self.assertDatasetIdentical(original, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpezxsf_.nc'

======================================================================
ERROR: test_roundtrip_example_1_netcdf (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 165, in test_roundtrip_example_1_netcdf
self.assertDatasetEqual(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpo5zwxy.nc'

======================================================================
ERROR: test_roundtrip_mask_and_scale (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 253, in test_roundtrip_mask_and_scale
self.assertDatasetAllClose(encoded, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmp5jczpa.nc'

======================================================================
ERROR: test_roundtrip_object_dtype (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 137, in test_roundtrip_object_dtype
self.assertDatasetIdentical(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpji2z1n.nc'

======================================================================
ERROR: test_roundtrip_string_data (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 144, in test_roundtrip_string_data
self.assertDatasetIdentical(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmp7sj2iu.nc'

======================================================================
ERROR: test_roundtrip_test_data (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 73, in test_roundtrip_test_data
self.assertDatasetAllClose(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpibvyaw.nc'

======================================================================
ERROR: test_write_store (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 68, in test_write_store
self.assertDatasetAllClose(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 588, in create_store
yield backends.ScipyDataStore(tmp_file, mode='w')
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpyy61n0.nc'

======================================================================
ERROR: test_zero_dimensional_variable (xray.test.test_backends.ScipyOnDiskDataTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 59, in test_zero_dimensional_variable
self.assertDatasetAllClose(expected, actual)
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 600, in roundtrip
yield ds
File "C:\Python27\Anaconda\lib\contextlib.py", line 24, in __exit__
self.gen.next()
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_backends.py", line 273, in create_tmp_file
os.remove(path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\breisfel\\appdata\\local\\temp\\tmpfqemcm.nc'

======================================================================
FAIL: test_coords (xray.test.test_dataarray.TestDataArray)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_dataarray.py", line 408, in test_coords
self.assertEquals(expected, actual)
AssertionError: 'Coordinates:\n  * x        (x) int64 -1 -2\n  * y        (y) int64 0 1 2' != 'Coordinates:\n  * x        (x) int32 -1 -2\n  * y        (y) int32 0 1 2'

======================================================================
FAIL: test_repr (xray.test.test_dataarray.TestDataArray)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_dataarray.py", line 34, in test_repr
self.assertEqual(expected, repr(data_array))
AssertionError: "<xray.DataArray 'my_variable' (time: 2, x: 3)>\narray([[1, 2, 3],\n       [4, 5, 6]])\nCoordinates:\n    other    int64 0\n  * time     (time) int64 0 1\n  * x        (x) int64 0 1 2\nAttributes:\n    foo: bar" != "<xray.DataArray 'my_variable' (time: 2, x: 3)>\narray([[1, 2, 3],\n       [4, 5, 6]])\nCoordinates:\n    other    int32 0\n  * time     (time) int64 0 1\n  * x        (x) int64 0 1 2\nAttributes:\n    foo: bar"

======================================================================
FAIL: test_coords_properties (xray.test.test_dataset.TestDataset)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_dataset.py", line 335, in test_coords_properties
self.assertEqual(expected, actual)
AssertionError: 'Coordinates:\n  * x        (x) int64 -1 -2\n  * y        (y) int64 0 1 2\n    a        (x) int64 4 5\n    b        int64 -10' != 'Coordinates:\n  * x        (x) int32 -1 -2\n  * y        (y) int32 0 1 2\n    a        (x) int32 4 5\n    b        int32 -10'

======================================================================
FAIL: test_to_and_from_dataframe (xray.test.test_dataset.TestDataset)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_dataset.py", line 1369, in test_to_and_from_dataframe
assert expected.equals(actual), (expected, actual)
AssertionError: (   a    x
y
0  1  bar,    a    x
y
0  1  bar)

======================================================================
FAIL: test_converted_types (xray.test.test_variable.TestAsCompatibleData)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_variable.py", line 813, in test_converted_types
self.assertEqual(np.dtype(int), actual.dtype)
AssertionError: dtype('int32') != dtype('int64')

======================================================================
FAIL: test_count (xray.test.test_variable.TestVariable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Anaconda\lib\site-packages\xray\test\test_variable.py", line 758, in test_count
self.assertEqual(actual.dtype, 'int64')
AssertionError: dtype('int32') != 'int64'

----------------------------------------------------------------------
Ran 368 tests in 5.705s

FAILED (SKIP=76, errors=11, failures=6)

# Fixed code
def dropna(self, dim, how="any", thresh=None, subset=None):
    """Returns a new dataset with dropped labels for missing values along
    the provided dimension.

    Parameters
    ----------
    dim : str
        Dimension along which to drop missing values. Dropping along
        multiple dimensions simultaneously is not yet supported.
    how : {'any', 'all'}, optional
        * any : if any NA values are present, drop that label
        * all : if all values are NA, drop that label
    thresh : int, default None
        If supplied, require this many non-NA values.
    subset : sequence, optional
        Subset of variables to check for missing values. By default, all
        variables in the dataset are checked.

    Returns
    -------
    Dataset
    """
    # TODO: consider supporting multiple dimensions? Or not, given that
    # there are some ugly edge cases, e.g., pandas's dropna differs
    # depending on the order of the supplied axes.

    if dim not in self.dims:
        raise ValueError("%s must be a single dataset dimension" % dim)

    if subset is None:
        subset = list(self.data_vars)

    count = np.zeros(self.dims[dim], dtype=np.int64)
    size = 0

    for k in subset:
        array = self._variables[k]
        if dim in array.dims:
            dims = [d for d in array.dims if d != dim]
            count += array.count(dims)
            size += np.prod([self.dims[d] for d in dims])

    if thresh is not None:
        mask = count >= thresh
    elif how == "any":
        mask = count == size
    elif how == "all":
        mask = count > 0
    elif how is not None:
        raise ValueError("invalid how option: %s" % how)
    else:
        raise TypeError("must specify how or thresh")

    return self.isel(**{dim: mask})