Skip to content

Harmonize encoding from h5netcdf with netcdf4 - #11067

Merged
kmuehlbauer merged 1 commit into
pydata:mainfrom
hmaarrfk:harmonize_h5netcdf_with_netcdf4
Jul 31, 2026
Merged

Harmonize encoding from h5netcdf with netcdf4#11067
kmuehlbauer merged 1 commit into
pydata:mainfrom
hmaarrfk:harmonize_h5netcdf_with_netcdf4

Conversation

@hmaarrfk

@hmaarrfk hmaarrfk commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

We were trying to figure why certain compression features were not included in our h5netcdf backend.

This PR to h5netcdf should provide the filters variable, but I understand that it is too bleeding edge for you all to pin to h5netcdf/h5netcdf#307

xref: #10657

Ultimately, I don't think you can change the backend without ensuring it is "drop in replacement" at least in what concerns metadata.
Critically, if you compress certain data with zstd, and you try to resave it, it would be saved as 'raw' ruining any gains you had from the compression.

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

I used AI (Claude) to help me fix the linter problems.

Comment on lines 270 to +274
"zlib",
"szip",
"bzip2",
"blosc",
"zstd",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: learn why this is a different bug?

Comment thread pixi.toml Outdated
distributed = "2024.6.*"
flox = "0.9.*"
h5netcdf = "1.3.*"
h5netcdf = "1.4.*"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo if #11068 doesn't get accepted

@hmaarrfk

hmaarrfk commented Jan 5, 2026

Copy link
Copy Markdown
Contributor Author

closing since being more aggressive seems to be ok
#10657 (comment)

@hmaarrfk hmaarrfk closed this Jan 5, 2026
@hmaarrfk hmaarrfk reopened this Jan 5, 2026
@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from c0d66e3 to 2006346 Compare January 5, 2026 21:10
@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from 0526993 to 25b1b0d Compare January 19, 2026 04:00

@kmuehlbauer kmuehlbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmaarrfk typo? It's h5netcdf 1.8.0

Comment thread pixi.toml Outdated
Comment thread pyproject.toml Outdated
@hmaarrfk

Copy link
Copy Markdown
Contributor Author

@hmaarrfk typo? It's h5netcdf 1.8.0

yes thanks, i kinda just played off memory.

@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from 8d8694a to 482a647 Compare March 24, 2026 21:08
Comment thread xarray/tests/test_backends.py Outdated
# tmp_file,
# engine="h5netcdf",
# encoding={"x": {"compression": "lzf", "zlib": True}},
# )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess i need to revive this error.

@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from 482a647 to 70833d0 Compare May 29, 2026 02:22
@github-actions github-actions Bot added the CI Continuous Integration tools label May 29, 2026
tmp_file,
engine="h5netcdf",
encoding={"x": {"compression": "lzf", "zlib": True}},
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, "compression": "lzf" wins now.

like test_compression_check_encoding_h5py

@hmaarrfk
hmaarrfk marked this pull request as ready for review May 29, 2026 12:20
@hmaarrfk

Copy link
Copy Markdown
Contributor Author

the CI should be fixed in #11366

@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from 70833d0 to ff1d4e0 Compare May 29, 2026 16:50
@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from ff1d4e0 to e4240a3 Compare June 19, 2026 01:32
@hmaarrfk

Copy link
Copy Markdown
Contributor Author

Just trying to see if there is still interest in this PR

@hmaarrfk

Copy link
Copy Markdown
Contributor Author

sorry to bump this again, i just think this is a small quality of life improvement when switching between backends.

@kmuehlbauer

Copy link
Copy Markdown
Contributor

Sorry for letting this sit around for so long, @hmaarrfk. This is looking good to me.

@keewis Any concerns with raising the minimum h5netcdf to version 1.8 (January 2026)?

@hmaarrfk

Copy link
Copy Markdown
Contributor Author

Thanks @kmuehlbauer.

Sorry to keep bumping this, but I think this is an important one that hits long time users of xarray.

I'm happy to help build and review a few of these maintenance PRs. let me know what else i can do to expedite this.

I given the 6 month thing, i would appreciate it if the final reviewer just rebased / merge to resolve the conflicts when they feel ready to do so.

I've been rebasing with AI alot and it just really helps. Let me know if you think that is unreasoable, so i can rebase after the final review.

@keewis

keewis commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

no concerns at all (sorry, I missed the ping a month ago). The min-deps CI says we can bump to 1.8 since January this year.

@kmuehlbauer, since you know the netcdf backends much better than I do feel free to merge whenever you think this is ready.

<details><summary>Claude's draft</summary>

Report compression and filter settings from the h5netcdf backend in the
variable ``encoding`` consistently with the netCDF4 backend, using
h5netcdf's ``Variable.filters()``. Data compressed with codecs such as
``zstd`` or ``blosc`` now keeps its compression when re-saved instead of
being silently written uncompressed.

- ``_extract_nc4_variable_encoding`` translates the boolean netCDF4-style
  compression flags (zlib/szip/bzip2/blosc/zstd) produced by
  ``filters()`` into a single h5py-style ``compression`` string. When both
  styles are supplied, the explicit ``compression`` takes precedence.
- Bump the minimum supported h5netcdf to 1.8.0 (which introduced these
  compatibility features) and add h5netcdf to the policy
  ``ignored_violations`` so the intentionally-newer pin does not fail the
  Minimum Version Policy check.
- Drop the now-unused ``requires_h5netcdf_1_7_0_or_above`` test helper.
- Document the change in whats-new.rst.

xref: pydata#10657

Co-authored-by: Claude <noreply@anthropic.com>

Resume this Claude session:
```
claude --resume 9faa34e9-aaf5-4e94-a2b7-b03f468175f8
```
</details>
@hmaarrfk
hmaarrfk force-pushed the harmonize_h5netcdf_with_netcdf4 branch from 1876e3a to 3a8d799 Compare July 31, 2026 02:24
@hmaarrfk

Copy link
Copy Markdown
Contributor Author

Cis refreshed and green.

@kmuehlbauer kmuehlbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mark! 🚀

@kmuehlbauer
kmuehlbauer merged commit d56e35c into pydata:main Jul 31, 2026
43 checks passed
charles-turner-1 pushed a commit to charles-turner-1/xarray that referenced this pull request Jul 31, 2026
<details><summary>Claude's draft</summary>

Report compression and filter settings from the h5netcdf backend in the
variable ``encoding`` consistently with the netCDF4 backend, using
h5netcdf's ``Variable.filters()``. Data compressed with codecs such as
``zstd`` or ``blosc`` now keeps its compression when re-saved instead of
being silently written uncompressed.

- ``_extract_nc4_variable_encoding`` translates the boolean netCDF4-style
  compression flags (zlib/szip/bzip2/blosc/zstd) produced by
  ``filters()`` into a single h5py-style ``compression`` string. When both
  styles are supplied, the explicit ``compression`` takes precedence.
- Bump the minimum supported h5netcdf to 1.8.0 (which introduced these
  compatibility features) and add h5netcdf to the policy
  ``ignored_violations`` so the intentionally-newer pin does not fail the
  Minimum Version Policy check.
- Drop the now-unused ``requires_h5netcdf_1_7_0_or_above`` test helper.
- Document the change in whats-new.rst.

xref: pydata#10657

Co-authored-by: Claude <noreply@anthropic.com>

Resume this Claude session:
```
claude --resume 9faa34e9-aaf5-4e94-a2b7-b03f468175f8
```
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants