Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataset encodings 'source' and 'original_shape' are not dropped in zarr backend #7129

Closed
4 tasks done
observingClouds opened this issue Oct 5, 2022 · 1 comment · Fixed by #7500
Closed
4 tasks done

Comments

@observingClouds
Copy link
Contributor

What happened?

When opening a dataset, like one from the tutorial, and writing it as zarr file, an error is raised due to encodings that are invalid for the zarr driver, when the encoding is given in to_zarr. In this particular case, the encodings source and original_shape are added by xarray itself, so that I expect that it can handle these encodings without raising an error.

What did you expect to happen?

I expect that the encodings source and original_shape being dropped similar to the netCDF4 backend.

Minimal Complete Verifiable Example

import xarray as xr
ds = xr.tutorial.load_dataset("eraint_uvz")
ds.to_zarr("test.zarr", encoding={"z":{**ds.z.encoding}})

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

>>> ds.to_zarr("test_w_offset.zarr01", encoding={"z":{**ds.z.encoding}})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../.conda/envs/xarray2022090/lib/python3.10/site-packages/xarray/core/dataset.py", line 2068, in to_zarr
    return to_zarr(  # type: ignore
  File ".../.conda/envs/xarray2022090/lib/python3.10/site-packages/xarray/backends/api.py", line 1653, in to_zarr
    dump_to_store(dataset, zstore, writer, encoding=encoding)
  File ".../.conda/envs/xarray2022090/lib/python3.10/site-packages/xarray/backends/api.py", line 1273, in dump_to_store
    store.store(variables, attrs, check_encoding, writer, unlimited_dims=unlimited_dims)
  File ".../.conda/envs/xarray2022090/lib/python3.10/site-packages/xarray/backends/zarr.py", line 574, in store
    self.set_variables(
  File ".../.conda/envs/xarray2022090/lib/python3.10/site-packages/xarray/backends/zarr.py", line 621, in set_variables
    encoding = extract_zarr_variable_encoding(
  File ".../.conda/envs/xarray2022090/lib/python3.10/site-packages/xarray/backends/zarr.py", line 247, in extract_zarr_variable_encoding
    raise ValueError(
ValueError: unexpected encoding parameters for zarr backend:  ['source', 'original_shape']

Anything else we need to know?

The respective lines in the netCDF4 backend are:

safe_to_drop = {"source", "original_shape"}

and

for k in safe_to_drop:
if k in encoding:
del encoding[k]

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:35:26) [GCC 10.4.0] python-bits: 64 OS: Linux OS-release: 4.18.0-305.25.1.el8_4.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: 4.8.1

xarray: 2022.9.0
pandas: 1.5.0
numpy: 1.23.3
scipy: None
netCDF4: 1.6.1
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.13.2
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.4.1
pip: 22.2.2
conda: None
pytest: None
IPython: 8.3.0
sphinx: None

@observingClouds observingClouds added bug needs triage Issue that has not been reviewed by xarray team member labels Oct 5, 2022
@dcherian
Copy link
Contributor

dcherian commented Jan 15, 2023

Yes this seems like a bug and should be easy to fix. PRs welcome!

@dcherian dcherian added topic-backends and removed needs triage Issue that has not been reviewed by xarray team member labels Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants