Skip to content

Commit

Permalink
🩹 Raise ModuleNotFoundError when xbatcher not installed (#37)
Browse files Browse the repository at this point in the history
Ensure that a helpful ModuleNotFoundError is raised when attempting to use XbatcherSlicer without xbatcher being installed.

* 🩹 Raise ModuleNotFoundError when xbatcher not installed

Left out on adding this if-statement in #22. So here's the patch!

* ✏️ Fix type hints for xbatcher and datashader source_datapipe

Need to use the full name xarray.DataArray instead of xr.DataArray to have the intersphinx link work.
  • Loading branch information
weiji14 authored Aug 14, 2022
1 parent 62b86a9 commit b871702
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion zen3geo/datapipes/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class XarrayCanvasIterDataPipe(IterDataPipe[Union[xr.DataArray, xr.Dataset]]):
Parameters
----------
source_datapipe : IterDataPipe[xr.DataArray]
source_datapipe : IterDataPipe[xarrray.DataArray]
A DataPipe that contains :py:class:`xarray.DataArray` or
:py:class:`xarray.Dataset` objects. These data objects need to have
both a ``.rio.x_dim`` and ``.rio.y_dim`` attribute, which is present
Expand Down
12 changes: 9 additions & 3 deletions zen3geo/datapipes/xbatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class XbatcherSlicerIterDataPipe(IterDataPipe[Union[xr.DataArray, xr.Dataset]]):
Parameters
----------
source_datapipe : IterDataPipe[xr.DataArray]
source_datapipe : IterDataPipe[xarray.DataArray]
A DataPipe that contains :py:class:`xarray.DataArray` or
:py:class:`xarray.Dataset` objects.
Expand Down Expand Up @@ -85,6 +85,12 @@ def __init__(
input_dims: Dict[Hashable, int],
**kwargs: Optional[Dict[str, Any]]
) -> None:
if xbatcher is None:
raise ModuleNotFoundError(
"Package `xbatcher` is required to be installed to use this datapipe. "
"Please use `pip install xbatcher` "
"to install the package"
)
self.source_datapipe: IterDataPipe[
Union[xr.DataArray, xr.Dataset]
] = source_datapipe
Expand All @@ -105,5 +111,5 @@ def __iter__(self) -> Iterator[Union[xr.DataArray, xr.Dataset]]:
):
yield chip

# def __len__(self) -> int:
# return len(self.source_datapipe)
# def __len__(self) -> int:
# return len(self.source_datapipe)

0 comments on commit b871702

Please sign in to comment.