Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 Raise ModuleNotFoundError when xbatcher not installed #37

Merged
merged 2 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)