Skip to content

Consistent GRIB handle usage in field#968

Merged
sandorkertesz merged 11 commits into
developfrom
feature/grib-handle-in-field
Apr 23, 2026
Merged

Consistent GRIB handle usage in field#968
sandorkertesz merged 11 commits into
developfrom
feature/grib-handle-in-field

Conversation

@sandorkertesz
Copy link
Copy Markdown
Collaborator

@sandorkertesz sandorkertesz commented Apr 22, 2026

Description

This PR implements the following changes for fields generated from GRIB messages:

  • when the metadata is changed with set() we cannot access any raw (GRIB) metadata on the new field. The reason for this is that the original GRIB message/handle is not updated when set() is called and it goes out of sync with the updated components of the field. Note: previously the (potentially out-of-sync) GRIB metadata was available on the modified field.
  • The raw (GRIB) metadata can be brought in sync with the field components by calling the newly added sync() method.
        >>> import earthkit.data as ekd
        >>> fl = ekd.from_source("sample", "test.grib").to_fieldlist()
        >>> f = fl[0]
        >>> f1 = f.set({"parameter.variable": "msl", "parameter.units": "Pa"})
        >>> f1.get("metadata.shortName")
        None
        >>> f1.metadata("shortName")
        KeyError: 'metadata.shortName' not found in field
        >>> f1.message()
        None
        >>> f2 = f1.sync()
        >>> f2.get("metadata.shortName")
        'msl'
        >>> f2.metadata("shortName")
        'msl'
        >>> f2.message()
        b'GRIB\x00\x ....

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 96.52778% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.64%. Comparing base (5eb79ea) to head (216b864).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
tests/encoders/test_grib_encoder.py 93.93% 3 Missing and 7 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #968      +/-   ##
===========================================
+ Coverage    81.26%   81.64%   +0.37%     
===========================================
  Files          223      226       +3     
  Lines        14624    14980     +356     
  Branches       718      745      +27     
===========================================
+ Hits         11884    12230     +346     
- Misses        2521     2524       +3     
- Partials       219      226       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sandorkertesz sandorkertesz changed the title Feature/grib handle in field Consistent GRIB handle usage in field Apr 23, 2026
@sandorkertesz sandorkertesz merged commit 645a86e into develop Apr 23, 2026
116 of 117 checks passed
@sandorkertesz sandorkertesz deleted the feature/grib-handle-in-field branch April 23, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants