MCPcopy
hub / github.com/pydata/xarray / test_chunk_key_encoding_v2

Method test_chunk_key_encoding_v2

xarray/tests/test_backends.py:4122–4153  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4120 yield {}
4121
4122 def test_chunk_key_encoding_v2(self) -> None:
4123 encoding = {"name": "v2", "configuration": {"separator": "/"}}
4124
4125 # Create a dataset with a variable name containing a period
4126 data = np.ones((4, 4))
4127 original = Dataset({"var1": (("x", "y"), data)})
4128
4129 # Set up chunk key encoding with slash separator
4130 encoding = {
4131 "var1": {
4132 "chunk_key_encoding": encoding,
4133 "chunks": (2, 2),
4134 }
4135 }
4136
4137 # Write to store with custom encoding
4138 with self.create_zarr_target() as store:
4139 original.to_zarr(store, encoding=encoding)
4140
4141 # Verify the chunk keys in store use the slash separator
4142 if not has_zarr_v3:
4143 chunk_keys = [k for k in store.keys() if k.startswith("var1/")]
4144 assert len(chunk_keys) > 0
4145 for key in chunk_keys:
4146 assert "/" in key
4147 assert "." not in key.split("/")[1:] # No dots in chunk coordinates
4148
4149 # Read back and verify data
4150 with xr.open_zarr(store) as actual:
4151 assert_identical(original, actual)
4152 # Verify chunks are preserved
4153 assert actual["var1"].encoding["chunks"] == (2, 2)
4154
4155 @pytest.mark.asyncio
4156 @requires_zarr_v3

Callers

nothing calls this directly

Calls 7

create_zarr_targetMethod · 0.95
to_zarrMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
keysMethod · 0.80
startswithMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected