()
| 7303 | @requires_fsspec |
| 7304 | @pytest.mark.filterwarnings("ignore:deallocating CachingFileManager") |
| 7305 | def test_open_fsspec() -> None: |
| 7306 | import fsspec |
| 7307 | |
| 7308 | if not ( |
| 7309 | ( |
| 7310 | hasattr(zarr.storage, "FSStore") |
| 7311 | and hasattr(zarr.storage.FSStore, "getitems") |
| 7312 | ) # zarr v2 |
| 7313 | or hasattr(zarr.storage, "FsspecStore") # zarr v3 |
| 7314 | ): |
| 7315 | pytest.skip("zarr too old") |
| 7316 | |
| 7317 | ds = open_dataset(os.path.join(os.path.dirname(__file__), "data", "example_1.nc")) |
| 7318 | |
| 7319 | m = fsspec.filesystem("memory") |
| 7320 | mm = m.get_mapper("out1.zarr") |
| 7321 | ds.to_zarr(mm) # old interface |
| 7322 | ds0 = ds.copy() |
| 7323 | # pd.to_timedelta returns ns-precision, but the example data is in second precision |
| 7324 | # so we need to fix this |
| 7325 | ds0["time"] = ds.time + np.timedelta64(1, "D") |
| 7326 | mm = m.get_mapper("out2.zarr") |
| 7327 | ds0.to_zarr(mm) # old interface |
| 7328 | |
| 7329 | # single dataset |
| 7330 | url = "memory://out2.zarr" |
| 7331 | ds2 = open_dataset(url, engine="zarr") |
| 7332 | xr.testing.assert_equal(ds0, ds2) |
| 7333 | |
| 7334 | # single dataset with caching |
| 7335 | url = "simplecache::memory://out2.zarr" |
| 7336 | ds2 = open_dataset(url, engine="zarr") |
| 7337 | xr.testing.assert_equal(ds0, ds2) |
| 7338 | |
| 7339 | # open_mfdataset requires dask |
| 7340 | if has_dask: |
| 7341 | # multi dataset |
| 7342 | url = "memory://out*.zarr" |
| 7343 | ds2 = open_mfdataset(url, engine="zarr") |
| 7344 | xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2) |
| 7345 | |
| 7346 | # multi dataset with caching |
| 7347 | url = "simplecache::memory://out*.zarr" |
| 7348 | ds2 = open_mfdataset(url, engine="zarr") |
| 7349 | xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2) |
| 7350 | |
| 7351 | |
| 7352 | @requires_h5netcdf |
nothing calls this directly
no test coverage detected
searching dependent graphs…