|
54 | 54 | requires_cfgrib,
|
55 | 55 | requires_cftime,
|
56 | 56 | requires_dask,
|
| 57 | + requires_fsspec, |
57 | 58 | requires_h5netcdf,
|
58 | 59 | requires_netCDF4,
|
59 | 60 | requires_pseudonetcdf,
|
@@ -3040,10 +3041,17 @@ def test_open_mfdataset(self):
|
3040 | 3041 |
|
3041 | 3042 | with raises_regex(IOError, "no files to open"):
|
3042 | 3043 | open_mfdataset("foo-bar-baz-*.nc")
|
3043 |
| - |
3044 | 3044 | with raises_regex(ValueError, "wild-card"):
|
3045 | 3045 | open_mfdataset("http://some/remote/uri")
|
3046 | 3046 |
|
| 3047 | + @requires_fsspec |
| 3048 | + def test_open_mfdataset_no_files(self): |
| 3049 | + pytest.importorskip("aiobotocore") |
| 3050 | + |
| 3051 | + # glob is attempted as of #4823, but finds no files |
| 3052 | + with raises_regex(OSError, "no files"): |
| 3053 | + open_mfdataset("http://some/remote/uri", engine="zarr") |
| 3054 | + |
3047 | 3055 | def test_open_mfdataset_2d(self):
|
3048 | 3056 | original = Dataset({"foo": (["x", "y"], np.random.randn(10, 8))})
|
3049 | 3057 | with create_tmp_file() as tmp1:
|
@@ -4799,6 +4807,48 @@ def test_extract_zarr_variable_encoding():
|
4799 | 4807 | )
|
4800 | 4808 |
|
4801 | 4809 |
|
| 4810 | +@requires_zarr |
| 4811 | +@requires_fsspec |
| 4812 | +def test_open_fsspec(): |
| 4813 | + import fsspec |
| 4814 | + import zarr |
| 4815 | + |
| 4816 | + if not hasattr(zarr.storage, "FSStore") or not hasattr( |
| 4817 | + zarr.storage.FSStore, "getitems" |
| 4818 | + ): |
| 4819 | + pytest.skip("zarr too old") |
| 4820 | + |
| 4821 | + ds = open_dataset(os.path.join(os.path.dirname(__file__), "data", "example_1.nc")) |
| 4822 | + |
| 4823 | + m = fsspec.filesystem("memory") |
| 4824 | + mm = m.get_mapper("out1.zarr") |
| 4825 | + ds.to_zarr(mm) # old interface |
| 4826 | + ds0 = ds.copy() |
| 4827 | + ds0["time"] = ds.time + pd.to_timedelta("1 day") |
| 4828 | + mm = m.get_mapper("out2.zarr") |
| 4829 | + ds0.to_zarr(mm) # old interface |
| 4830 | + |
| 4831 | + # single dataset |
| 4832 | + url = "memory://out2.zarr" |
| 4833 | + ds2 = open_dataset(url, engine="zarr") |
| 4834 | + assert ds0 == ds2 |
| 4835 | + |
| 4836 | + # single dataset with caching |
| 4837 | + url = "simplecache::memory://out2.zarr" |
| 4838 | + ds2 = open_dataset(url, engine="zarr") |
| 4839 | + assert ds0 == ds2 |
| 4840 | + |
| 4841 | + # multi dataset |
| 4842 | + url = "memory://out*.zarr" |
| 4843 | + ds2 = open_mfdataset(url, engine="zarr") |
| 4844 | + assert xr.concat([ds, ds0], dim="time") == ds2 |
| 4845 | + |
| 4846 | + # multi dataset with caching |
| 4847 | + url = "simplecache::memory://out*.zarr" |
| 4848 | + ds2 = open_mfdataset(url, engine="zarr") |
| 4849 | + assert xr.concat([ds, ds0], dim="time") == ds2 |
| 4850 | + |
| 4851 | + |
4802 | 4852 | @requires_h5netcdf
|
4803 | 4853 | def test_load_single_value_h5netcdf(tmp_path):
|
4804 | 4854 | """Test that numeric single-element vector attributes are handled fine.
|
|
0 commit comments