Repository navigation
Conversation
xarray now imports inside get_root_dims, its only use site; openpyxl imports moved into the Excel output path. Closes nasa#374.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Defers heavy xarray and openpyxl imports to reduce CLI startup time.
Changes:
- Lazily imports
xarrayfor dimension inspection. - Lazily imports
openpyxlfor Excel output. - Adds a subprocess regression test for import behavior.
| File | Description |
|---|---|
tests/test_imports.py |
Verifies deferred imports remain unloaded. |
ncompare/printing.py |
Defers Excel dependencies. |
ncompare/getters.py |
Defers the xarray dependency. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fixes the W292 finding from the pre-commit ruff hook.
This branch has not been deployed
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.
GitHub Issue: #374
Description
import ncompareno longer loads xarray (with pandas) or openpyxl at importtime. xarray moved into
get_root_dims, openpyxl into the Excel output path.Module-level
h5pyandnetCDF4imports are untouched, so the #363import-order question is unaffected.
Local test steps
uv run pytest: 26 passed, 2 integration deselected (Python 3.11, macOS)uv run ruff check ncompare: cleanpython -X importtime -c "import ncompare": 214 ms to 58 ms warm;fixture CLI run 0.47 s to 0.23 s
sys.modulesafter
import ncompare(runs in a fresh interpreter, since the suiteimports xarray)
Overview of integration done
Golden-file tests cover text, CSV, and XLSX output, so both deferred paths
run end to end and pass.
PR Acceptance Checklist
CHANGELOG.mdupdated (entries added at release time)📚 Documentation preview 📚: https://ncompare--375.org.readthedocs.build/en/375/