Skip to content

Commit

Permalink
Add test to reproduce GH 2815
Browse files Browse the repository at this point in the history
  • Loading branch information
gerritholl committed Jun 14, 2024
1 parent 367016e commit 7f6a8d4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions satpy/tests/reader_tests/test_netcdf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,40 @@ def test_get_data_as_xarray_scalar_h5netcdf(tmp_path):
res = get_data_as_xarray(fid["test_data"])
np.testing.assert_equal(res.data, np.array(data))
assert res.attrs == NC_ATTRS


@pytest.fixture()
def dummy_nc(tmp_path):
"""Fixture to create a dummy NetCDF file and return its path."""
import xarray as xr

fn = tmp_path / "sjaunja.nc"
ds = xr.Dataset(data_vars={"kaitum": (["x"], np.arange(10))})
ds.to_netcdf(fn)
return fn


def test_caching_distributed(dummy_nc):
"""Test that the distributed scheduler works with file handle caching.
This is a test for GitHub issue 2815.
"""
from dask.distributed import Client

from satpy.readers.netcdf_utils import NetCDF4FileHandler

fh = NetCDF4FileHandler(dummy_nc, {}, {}, cache_handle=True)

Client()

def doubler(x):
return x * 2

# As documented in GH issue 2815, using dask distributed with the file
# handle cacher might fail in non-trivial ways, such as giving incorrect
# results. Testing map_blocks is one way to reproduce the problem
# reliably, even though the problem also manifests itself (in different
# ways) without map_blocks.

dask_doubler = fh["kaitum"].map_blocks(doubler)
dask_doubler.compute()

0 comments on commit 7f6a8d4

Please sign in to comment.