Skip to content

Commit

Permalink
Fix h5netcdf saving scalars with filters or chunks (pydata#2591)
Browse files Browse the repository at this point in the history
* Fix h5netcdf saving scalars with filters or chunks

* Revert adding scalar dataset to central test function

* Add fix description to what's new.
  • Loading branch information
mraspaud authored and shoyer committed Dec 11, 2018
1 parent 77634d4 commit 53746c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Enhancements
Bug fixes
~~~~~~~~~

- Fix h5netcdf saving scalars with filters or chunks (:issue:`2563`).
By `Martin Raspaud <https://github.com/mraspaud>`_.

.. _whats-new.0.11.0:

v0.11.0 (7 November 2018)
Expand Down
10 changes: 6 additions & 4 deletions xarray/backends/h5netcdf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ def prepare_variable(self, name, variable, check_encoding=False,

encoding['chunks'] = encoding.pop('chunksizes', None)

for key in ['compression', 'compression_opts', 'shuffle',
'chunks', 'fletcher32']:
if key in encoding:
kwargs[key] = encoding[key]
# Do not apply compression, filters or chunking to scalars.
if variable.shape:
for key in ['compression', 'compression_opts', 'shuffle',
'chunks', 'fletcher32']:
if key in encoding:
kwargs[key] = encoding[key]
if name not in self.ds:
nc4_var = self.ds.create_variable(
name, dtype=dtype, dimensions=variable.dims,
Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,8 @@ def test_compression_encoding_h5py(self):
data['var2'].encoding.update(compr_in)
data['var2'].encoding.update(compr_common)
compr_out.update(compr_common)
data['scalar'] = ('scalar_dim', np.array([2.0]))
data['scalar'] = data['scalar'][0]
with self.roundtrip(data) as actual:
for k, v in compr_out.items():
assert v == actual['var2'].encoding[k]
Expand Down

0 comments on commit 53746c9

Please sign in to comment.