diff --git a/CHANGES.md b/CHANGES.md index cec380a..456457d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,12 +1,22 @@ ## Version 0.1.2 (in development) +### Enhancements + * Introduced new configuration flag `persist_mem_slices`. If set, in-memory `xr.Dataset` instances will be first persisted to a temporary Zarr, then reopened, and then appended to the target dataset. [#11] -* Fixed problem where info about closing slice was logged twice. [#9] * Improved readability of generated configuration documentation. * Using `requirements-dev.txt` for development package dependencies. +### Fixes + +* Fixed problem when passing slices opened from NetCDF files. The error was + `TypeError: VariableEncoding.__init__() got an unexpected keyword argument 'chunksizes'`. + [#14] + +* Fixed problem where info about closing slice was logged twice. [#9] + + ## Version 0.1.1 Metadata fixes in `setup.cfg`. No actual code changes. diff --git a/tests/test_metadata.py b/tests/test_metadata.py index c113c4d..ad20e98 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -238,6 +238,40 @@ def test_variable_defaults(self): ).to_dict(), ) + def test_variable_encoding_from_netcdf(self): + a = xr.DataArray(np.zeros((2, 3, 4)), dims=("time", "y", "x")) + a.encoding.update(chunksizes=(16, 2, 2)) # turned into "chunks" + b = xr.DataArray(np.zeros((2, 3, 4)), dims=("time", "y", "x")) + b.encoding.update(contiguous=True, endian="big") # logs warning + self.assertEqual( + { + "attrs": {}, + "dims": {"time": 2, "x": 4, "y": 3}, + "variables": { + "a": { + "attrs": {}, + "dims": ("time", "y", "x"), + "encoding": {"chunks": (16, 2, 2)}, + "shape": (2, 3, 4), + }, + "b": { + "attrs": {}, + "dims": ("time", "y", "x"), + "encoding": {}, + "shape": (2, 3, 4), + }, + }, + }, + DatasetMetadata.from_dataset( + xr.Dataset( + { + "a": a, + "b": b, + } + ) + ).to_dict(), + ) + def test_variable_encoding_normalisation(self): def normalize(k, v): metadata = DatasetMetadata.from_dataset( diff --git a/zappend/metadata.py b/zappend/metadata.py index a1e4f9f..f812761 100644 --- a/zappend/metadata.py +++ b/zappend/metadata.py @@ -10,6 +10,7 @@ import xarray as xr from .config import merge_configs, DEFAULT_APPEND_DIM +from .log import logger class Undefined: @@ -34,6 +35,7 @@ def __init__( calendar: str | Undefined = UNDEFINED, compressor: Codec | None | Undefined = UNDEFINED, filters: list[Codec] | None | Undefined = UNDEFINED, + **unknown_settings, ): """All arguments default to UNDEFINED, so they can be distinguished from None, which is has a special meaning for some values. @@ -47,6 +49,8 @@ def __init__( self.calendar = calendar self.compressor = compressor self.filters = filters + if unknown_settings: + logger.warning("Ignoring unknown encoding settings: %s", unknown_settings) def to_dict(self): d = { @@ -271,6 +275,10 @@ def _get_effective_variables( encoding["fill_value"] = fill_value if "preferred_chunks" in encoding: encoding.pop("preferred_chunks") + if "chunksizes" in encoding: + chunk_sizes = encoding.pop("chunksizes") + if "chunks" not in encoding: + encoding["chunks"] = chunk_sizes variables[var_name] = VariableMetadata( dims=dims, shape=shape, encoding=VariableEncoding(**encoding), attrs=attrs )