Skip to content

Harden code, improve tests, and consolidate test suite - #95

Merged
bbakernoaa merged 11 commits into
NOAA-EMC:mainfrom
bbakernoaa:main
May 12, 2026
Merged

Harden code, improve tests, and consolidate test suite#95
bbakernoaa merged 11 commits into
NOAA-EMC:mainfrom
bbakernoaa:main

Conversation

@bbakernoaa

Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements and enhancements to the xregrid package, focusing on robustness, memory management, and developer usability. The changes include enhanced error handling for ESMF regridding initialization, new cache management methods for better memory control in distributed/Dask environments, improved robustness for edge cases in the core regridding logic, and expanded documentation for CLI and internal APIs. Additionally, the pull request removes several test files, likely as part of a test suite reorganization.

Key changes:

Robustness and Error Handling

  • Added robust error handling for ESMF regrid object initialization in both the parallel and serial code paths. Now, specific error messages are raised for common ESMF errors, and errors are propagated in parallel execution, improving debuggability and user feedback. [1] [2]
  • Improved handling of edge cases in _apply_weights_core to return all-NaN arrays when the input data is empty or has no spatial elements, preventing shape or calculation errors.

Cache and Memory Management

  • Introduced new methods to clear global and instance-specific caches for regridder objects, including support for clearing worker-local caches in Dask distributed environments. Also added automatic cache cleanup in the Regridder destructor. This helps prevent memory leaks in long-running or parallelized workflows. [1] [2] [3]

CLI and API Documentation

  • Added docstrings and type annotations to the CLI entry points (parse_args, main) for improved developer clarity and maintainability. [1] [2]

Mask and Grid Handling

  • Improved mask variable handling in grid creation to robustly select the appropriate slice for the mask variable, especially when non-spatial dimensions are present.

Test Suite Reorganization

  • Removed a large number of test files, likely as part of a test suite cleanup or migration. These files covered a wide range of functionality, including core algorithms, auxiliary coordinate handling, bounds, CF-awareness, and more. [1] [2] [3] [4] [5]

Other minor changes include a small update to the README.md to clarify the project description.

bbakernoaa and others added 9 commits May 9, 2026 07:33
- Refactor `.values` calls in `grid.py` to maintain Dask laziness for mask handling.
- Implement `Regridder.clear_cache()` and `clear_instance_cache()` for improved memory management.
- Add `__del__` to `Regridder` to ensure automatic cleanup of worker-local caches.
- Improve ESMF error handling by translating cryptic codes into descriptive messages.
- Harden `_apply_weights_core` to handle empty or NaN-only input arrays gracefully.
- Add comprehensive new tests for hardening verification, Aero Protocol compliance, and cache isolation.
- Format codebase with `ruff`.
- Resolved formatting issues in test files and core logic.
- Added missing NumPy-style docstrings and type hints to CLI and internal functions.
- Verified that all unit tests pass with both Eager and Lazy backends.
- Ensured compliance with the Aero Protocol for backend-agnostic computation.
- Verified that pre-commit hooks (ruff, ruff-format) pass completely.
Moved approximately 70 fragmented test files into 11 categorical files:
- test_backends.py
- test_diagnostics.py
- test_grids.py
- test_integration.py
- test_misc.py
- test_optimization.py
- test_protocol.py
- test_regridder.py
- test_unstructured.py
- test_utils.py
- test_viz.py

Each file contains migrated test functions and classes, with name conflicts
resolved by appending suffixes. Shared fixtures like dask_client and
sample_input were preserved. All original test_aero_*.py and other redundant
test files were removed to improve repository structure and maintainability.
…8799792

Consolidate and logically name test suite
- Add Architecture overview with Mermaid diagram to index.md
- Create Scientific Hygiene guide (Aero Protocol, NaN handling, diagnostics)
- Document xarray accessors in new accessors.md
- Complete missing grid generation utilities in utils.md
- Update navigation and examples README
- Fix SyntaxError and missing import in tests/test_utils.py
Harden Documentation and Scientific Guides
@bbakernoaa

Copy link
Copy Markdown
Collaborator Author

@jules can you help

- Replace star imports with explicit imports in `tests/test_utils.py`.
- Fix bare except in `tests/test_utils.py`.
- Remove redundant empty test files that only contained star imports and no tests.
- Consolidate ESMF check logic in `tests/test_utils.py`.
- Ensure compliance with `ruff` linting rules.
@bbakernoaa
bbakernoaa merged commit 9d8c549 into NOAA-EMC:main May 12, 2026
3 checks passed
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.

1 participant