Author of Proposal: @brendancol
Reason or problem
datashader is a core dependency in setup.cfg, but the library barely uses it:
terrain.py and datasets/__init__.py use ds.Canvas.points on an empty DataFrame just to generate coordinate arrays (there's a comment calling it hack_agg)
utils.py wraps ds.Canvas.raster in canvas_like() and uses tf.Image in two visualization helpers (bands_to_img, color_values)
test_viewshed.py uses ds.Canvas to build a test fixture
Datashader drags in bokeh, colorcet, panel, param, and more. That's a lot of transitive weight for users who just want raster math.
Separately, esri.py has REST-client utilities for querying ArcGIS feature services. Nothing in the codebase imports it, __init__.py doesn't re-export it, and there are no tests. It also pulls in requests as an undeclared dependency. It shouldn't be here.
Proposal
Design:
-
Delete esri.py. Nothing references it.
-
Remove datashader from install_requires in setup.cfg. Add it to [options.extras_require] examples so notebook users can still get it via pip install xarray-spatial[examples].
-
Replace the ds.Canvas coordinate hacks in terrain.py and datasets/__init__.py with np.linspace. The current code creates a Canvas, calls .points() on an empty DataFrame, and steals the coords from the result. We can build the coordinate arrays directly.
-
Swap tf.Image in bands_to_img() and color_values() for PIL.Image (Pillow), already available via matplotlib.
-
Replace datashader.colors.rgb() in color_values() with a local hex-to-RGB helper.
-
Make canvas_like() lazy-import datashader and raise a clear ImportError if missing. This function wraps cvs.raster() and there's no drop-in replacement.
-
Update test_viewshed.py to build its fixture DataArray with np.linspace coordinates.
-
Update the docstring example in zonal.py to note that datashader is optional.
Usage:
pip install xarray-spatial will no longer pull in datashader. Users who need canvas_like() or the example notebooks can install extras: pip install xarray-spatial[examples].
Value:
Lighter install and fewer version conflicts. Removes dead code.
Stakeholders and impacts
All downstream users get a lighter install. The only functions affected are canvas_like, bands_to_img, and color_values -- visualization helpers, not core spatial algorithms.
Drawbacks
canvas_like will raise ImportError if datashader isn't installed. Users who depend on it need to add datashader to their own requirements.
bands_to_img and color_values will return PIL.Image objects instead of datashader.transfer_functions.Image. Both are PIL subclasses in practice, so most downstream code should work fine.
Alternatives
- Lazy-import datashader everywhere with try/except. Adds complexity for little benefit when the core library doesn't need it.
- Move datashader to
extras_require only. That's what this proposal does for canvas_like; the rest gets replaced outright.
Unresolved questions
None.
Additional notes
Removing esri.py also eliminates an undeclared requests dependency.
Author of Proposal: @brendancol
Reason or problem
datashaderis a core dependency insetup.cfg, but the library barely uses it:terrain.pyanddatasets/__init__.pyuseds.Canvas.pointson an empty DataFrame just to generate coordinate arrays (there's a comment calling ithack_agg)utils.pywrapsds.Canvas.rasterincanvas_like()and usestf.Imagein two visualization helpers (bands_to_img,color_values)test_viewshed.pyusesds.Canvasto build a test fixtureDatashader drags in bokeh, colorcet, panel, param, and more. That's a lot of transitive weight for users who just want raster math.
Separately,
esri.pyhas REST-client utilities for querying ArcGIS feature services. Nothing in the codebase imports it,__init__.pydoesn't re-export it, and there are no tests. It also pulls inrequestsas an undeclared dependency. It shouldn't be here.Proposal
Design:
Delete
esri.py. Nothing references it.Remove
datashaderfrominstall_requiresinsetup.cfg. Add it to[options.extras_require] examplesso notebook users can still get it viapip install xarray-spatial[examples].Replace the
ds.Canvascoordinate hacks interrain.pyanddatasets/__init__.pywithnp.linspace. The current code creates a Canvas, calls.points()on an empty DataFrame, and steals the coords from the result. We can build the coordinate arrays directly.Swap
tf.Imageinbands_to_img()andcolor_values()forPIL.Image(Pillow), already available via matplotlib.Replace
datashader.colors.rgb()incolor_values()with a local hex-to-RGB helper.Make
canvas_like()lazy-import datashader and raise a clearImportErrorif missing. This function wrapscvs.raster()and there's no drop-in replacement.Update
test_viewshed.pyto build its fixture DataArray withnp.linspacecoordinates.Update the docstring example in
zonal.pyto note that datashader is optional.Usage:
pip install xarray-spatialwill no longer pull in datashader. Users who needcanvas_like()or the example notebooks can install extras:pip install xarray-spatial[examples].Value:
Lighter install and fewer version conflicts. Removes dead code.
Stakeholders and impacts
All downstream users get a lighter install. The only functions affected are
canvas_like,bands_to_img, andcolor_values-- visualization helpers, not core spatial algorithms.Drawbacks
canvas_likewill raiseImportErrorif datashader isn't installed. Users who depend on it need to add datashader to their own requirements.bands_to_imgandcolor_valueswill returnPIL.Imageobjects instead ofdatashader.transfer_functions.Image. Both are PIL subclasses in practice, so most downstream code should work fine.Alternatives
extras_requireonly. That's what this proposal does forcanvas_like; the rest gets replaced outright.Unresolved questions
None.
Additional notes
Removing
esri.pyalso eliminates an undeclaredrequestsdependency.