Repository navigation
Forcing.from_csv: import importlib.resources explicitly - #61
Merged
Merged
Conversation
forcing.py imported only the top-level `importlib` package but called `importlib.resources.files(...)`. That attribute exists only once some other module has imported `importlib.resources`, so `Forcing.from_csv(dataset=...)` raised AttributeError in a fresh interpreter (e.g. a plain script). Adds a regression test that loads both bundled datasets in a subprocess, since an in-process test can pass by accident when the submodule is already loaded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
forcing.pydoesimport importlibbut callsimportlib.resources.files(...). Theresourcessubmodule is only an attribute ofimportlibonce something else has imported it, so in a fresh interpreter:Found while scripting Fig. 1 of the GMD paper (which currently works around it).
Fix
import importlib→import importlib.resources(one line).tests/test_core_forcing_datasets.py: loads both bundled datasets (insolation,vieira_tsi) in a subprocess. An in-process test can pass by accident when pytest or another package has already loadedimportlib.resources. The test fails without the fix and passes with it.Full suite: 457 passed.
🤖 Generated with Claude Code