Skip to content

Refactor dependencies to make more optional#1548

Draft
Sevans711 wants to merge 3 commits into
mainfrom
refactor-optional-dependencies
Draft

Refactor dependencies to make more optional#1548
Sevans711 wants to merge 3 commits into
mainfrom
refactor-optional-dependencies

Conversation

@Sevans711

@Sevans711 Sevans711 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #1224

Waiting for #1541 before asking to merge (in order to move hvplot from required to "viz").

Overview

Addresses user feedback asking to handle dependencies in a more elegant manner. Many previously-required dependencies are now optional. Also may speed up "import uxarray" slightly, as now-optional dependencies are moved to no longer be at top-level / top of files; instead, they are imported the first time any relevant method gets called. Imports of some required dependencies were similarly moved, to possibly improve "import uxarray" timing.

Notes about all dependencies which were previously listed as required in pyproject.toml:

  • antimeridian: important for geometry → keep as required. [EFF] Efficiency note: antimeridian was already never being imported at top-level.
  • cartopy: used only in plotting → viz
  • dask[dataframe]: keep as required for now. But, it is only used in core.aggrecation and core.zonal, so maybe could make optional? [EFF] already never at top-level.
  • datashader: not used explicitly anywhere → removed
  • geoviews: used only in examples, for plotting → viz
  • holoviews: used only in examples, tests, and HoloviewsBackend for plotting → viz
  • matplotlib: used only for plotting → viz
  • matplotlib-inline: not used explicitly anywhere → removed
  • netcdf4: not used explicitly, but everyone is reading .nc files → keep as required
  • numba: keep as required, of course
  • numpy: keep as required, of course
  • pandas: important for grid methods, e.g. pd.Series and pd.IntervalIndex used explicitly → keep as required
  • pyarrow: not used explicitly, and dask[dataframe] already depends on it → removed
  • requests: not used explicitly anywhere in uxarray → removed
  • scikit-learn: important for neighbor algorithms, e.g. KDTree → keep as required. [EFF] already not at top-level.
  • scipy: important for delaunay triangulations and some io → keep as required. [EFF] removed from top-level.
  • shapely: important for geometry → keep as required. [EFF] already not at top-level.
  • spatialpandas: just for spatialpandas.GeoDataFrame conversions; should be optional → geo
  • geopandas: just for geopandas.GeoDataFrame conversions; should be optional → geo
  • xarray: keep as required, of course
  • hvplot: used only for plotting → viz. Didn't move it yet though; waiting for Speed up import and load hvplot lazily #1541 to get merged
  • healpix: just for healpix grids; should be optional → geo
  • polars: used explicitly for some internal methods → keep as required
  • pyproj: only used in uxarray.cross_sections.sample.sample_geodesic; should be optional → geo

Miscellaneous notes:

  • removed pathlib; pathlib became a built-in part of the standard library in Python 3.4, and the pyproject.toml requires Python >= 3.10.
  • added "all" as alias for "complete" because many libraries use "all"; see example usage below.
  • added pooch to "dev" dependency group, because pooch was secretly required in order for all tests to pass. Comment in test/io/test_structure.py clarifies why pooch dependency exists despite not being imported explicitly anywhere in uxarray.

Expected Usage

Users can now install uxarray with optional dependency groups. Simple examples with pip interface:
Required dependencies only:

pip install uxarray

Also includes all optional dependencies related to geospatial grids (geopandas, healpix, pyproj, spatialpandas)

pip install "uxarray[geo]"

Also includes everything related to geospatial grids, plus everything related to visualization (cartopy, geoviews, holoviews, matplotlib)

pip install "uxarray[geo,viz]"

Includes all required plus all optional dependencies:

pip install "uxarray[complete]"

Equivalent to above: pip install "uxarray[all]"

PR Checklist

General

  • An issue is linked created and linked
  • Add appropriate labels
  • Filled out Overview and Expected Usage (if applicable) sections

Testing

  • Adequate tests are created if there is new functionality
  • Tests cover all possible logical paths in your function
  • Tests are not too basic (such as simply calling a function and nothing else)
  • Question: should we add something to test suite to ensure you can at least import uxarray after doing pip install uxarray with minimal dependencies? We could maybe add a few more tests for different combinations of dependencies too?

Related to #1224; addresses user feedback asking to handle dependencies in a more elegant manner. Many previously-required dependencies are now optional. Also may speed up "import uxarray" slightly, as now-optional dependencies are moved to no longer be at top of files; instead, they are imported the first time any relevant method gets called.

See upcoming associated PR for more notes / reasoning / discussion.
@Sevans711 Sevans711 added the dependencies Pull requests that update a dependency file label Jul 6, 2026
Sevans711 added 2 commits July 6, 2026 14:35
(copilot suggestions hallucinated a strange import, this commit fixes that.)
Missed an import of GeoAxes, while refactoring to remove required dependencies.

Added pooch dependency, which is necessary for test/io/test_structure.py tests to run, and previously was not included anywhere in dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependency Refactor & Organization

1 participant