Skip to content

Lazy-import visualization and xarray to avoid eager heavy dependencies#210

Merged
ttuff merged 1 commit intomainfrom
codex/fix-compatibility-issues-with-numpy-2.x
Mar 28, 2026
Merged

Lazy-import visualization and xarray to avoid eager heavy dependencies#210
ttuff merged 1 commit intomainfrom
codex/fix-compatibility-issues-with-numpy-2.x

Conversation

@ttuff
Copy link
Copy Markdown
Contributor

@ttuff ttuff commented Mar 28, 2026

Motivation

  • Prevent the heavy visualization stack and xarray from being imported at package import time to reduce import-time failures and overhead.
  • Provide backward-compatible verb/utility functions that only load visualization code when actually invoked.

Description

  • Stop importing xarray eagerly in cubedynamics.__init__ by guarding the import with typing.TYPE_CHECKING and remove top-level viz imports; add lazy wrappers show_cube_lexcube and plot_median_over_space that import the real viz functions on call.
  • In cubedynamics.verbs, remove top-level cubedynamics.viz and xarray imports and introduce a helper _import_xarray() for lazy xarray loading, and import cubedynamics.viz inside the show_cube_lexcube verb implementation.
  • Adjust _unwrap_dataarray signature to avoid referencing xr at import time and use _import_xarray() where runtime access to xarray is required.
  • Add a unit test tests/test_verbs_import_no_eager_viz.py that verifies importing cubedynamics.verbs does not eagerly load cubedynamics.viz or cubedynamics.viz.lexcube_viz.

Testing

  • Added and ran the unit test tests/test_verbs_import_no_eager_viz.py, which asserts that importing cubedynamics.verbs does not place cubedynamics.viz or cubedynamics.viz.lexcube_viz into sys.modules, and the test passed.

Codex Task

@ttuff ttuff merged commit 721f2e6 into main Mar 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant