Repository navigation
Conversation
- Guard against `None` restart dates in grav_subs_maps, grav_subs_points and fluxfile_obj - Use `Sequence[datetime.datetime]` for date types in restartthinner - Annotate `Any` for flux and EGRID file objects in sector2fluxnum - Use `get_num_lgr()` instead of the deprecated `getNumLGR()` - Replace `cwrap.open` with built-in `open` and drop the cwrap import - Remove the `cwrap` mypy ignore override from pyproject.toml - Correct the `split_vectorsdatafiles` return type to list `Summary`
There was a problem hiding this comment.
🟡 Changes recommended
The restart-date guard still permits an IndexError when source_restart.dates is None, so missing dates need validation and an explicit error before indexing.
1 open issue
What changed in this PR
This PR addresses lint and type-check errors across Subscript’s simulation-data utilities by refining annotations and updating API usage.
Changes:
- Adjust restart-date handling and date-sequence annotations.
- Correct summary return types and annotate flux/EGRID objects.
- Replace deprecated grid and file-opening APIs, and remove the
cwrapmypy override.
| File | Description |
|---|---|
src/subscript/summaryplot/summaryplot.py |
Corrects annotations to identify returned Summary objects. |
src/subscript/sector2fluxnum/sector2fluxnum.py |
Replaces cwrap.open with built-in open. |
src/subscript/sector2fluxnum/fluxfile_obj.py |
Updates grid API calls, flux typing, and restart-date handling. |
src/subscript/sector2fluxnum/flux_obj.py |
Adds an Any alias for EGRID access. |
src/subscript/restartthinner/restartthinner.py |
Uses Sequence[datetime.datetime] for date annotations. |
src/subscript/grav_subs_points/grav_subs_points.py |
Allows iteration when restart dates are None. |
src/subscript/grav_subs_maps/grav_subs_maps.py |
Allows iteration when restart dates are None. |
pyproject.toml |
Removes the cwrap missing-import override. |
Review effort: Balanced
- Replace silent fallback to an empty list with an explicit ValueError - Avoid an IndexError when accessing the first restart date
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #895 +/- ##
==========================================
- Coverage 84.47% 84.47% -0.01%
==========================================
Files 49 49
Lines 7570 7574 +4
==========================================
+ Hits 6395 6398 +3
- Misses 1175 1176 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Replace index access on EGRID and flux files with iget_kw calls - Drop the Any type annotations that were hiding typing errors - Cache the keyword in kw_fine within the flux writing loop
| "ert", | ||
| "grid3d_maps.*", | ||
| "fmu.tools.*", | ||
| "cwrap", |
There was a problem hiding this comment.
Do you know why we used cwrap before and why it is failing now?
There was a problem hiding this comment.
cwrap is a Python library for wrapping C code through ctypes. In older resdata, which came from the ecl library, the Python classes called C functions through it. The C code wrote GRDECL files through a C FILE*, so a normal Python file handle wouldn't work. cwrap.open() returns a file object that exposes the underlying FILE*. That's why subscript used it for write_grdecl (it's been there since at least b6c2e076).
It fails now because resdata 7 reimplemented the I/O in Python and compiled extension modules. write_grdecl and read_grdecl now take ordinary io.TextIOWrapper handles, and cwrap is no longer in resdata's dependencies. Nothing else installs it, so the CI environment lacks it and the import fails.

Nonerestart dates in grav_subs_maps, grav_subs_points and fluxfile_objSequence[datetime.datetime]for date types in restartthinnerAnyfor flux and EGRID file objects in sector2fluxnumget_num_lgr()instead of the deprecatedgetNumLGR()cwrap.openwith built-inopenand drop the cwrap importcwrapmypy ignore override from pyproject.tomlsplit_vectorsdatafilesreturn type to listSummary