Refactor dependencies to make more optional#1548
Draft
Sevans711 wants to merge 3 commits into
Draft
Conversation
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.
(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.
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.
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 → vizdask[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 → removedgeoviews: used only in examples, for plotting → vizholoviews: used only in examples, tests, and HoloviewsBackend for plotting → vizmatplotlib: used only for plotting → vizmatplotlib-inline: not used explicitly anywhere → removednetcdf4: not used explicitly, but everyone is reading .nc files → keep as requirednumba: keep as required, of coursenumpy: keep as required, of coursepandas: important for grid methods, e.g. pd.Series and pd.IntervalIndex used explicitly → keep as requiredpyarrow: not used explicitly, and dask[dataframe] already depends on it → removedrequests: not used explicitly anywhere in uxarray → removedscikit-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 → geogeopandas: just for geopandas.GeoDataFrame conversions; should be optional → geoxarray: keep as required, of coursehvplot: used only for plotting → viz. Didn't move it yet though; waiting for Speed up import and load hvplot lazily #1541 to get mergedhealpix: just for healpix grids; should be optional → geopolars: used explicitly for some internal methods → keep as requiredpyproj: only used in uxarray.cross_sections.sample.sample_geodesic; should be optional → geoMiscellaneous notes:
pathlib; pathlib became a built-in part of the standard library in Python 3.4, and the pyproject.toml requires Python >= 3.10.poochto "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:
Also includes all optional dependencies related to geospatial grids (geopandas, healpix, pyproj, spatialpandas)
Also includes everything related to geospatial grids, plus everything related to visualization (cartopy, geoviews, holoviews, matplotlib)
Includes all required plus all optional dependencies:
Equivalent to above:
pip install "uxarray[all]"PR Checklist
General
Testing
import uxarrayafter doingpip install uxarraywith minimal dependencies? We could maybe add a few more tests for different combinations of dependencies too?