Skip to content

Commit

Permalink
Do not raise if custom renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Aug 2, 2024
1 parent 92d2c5e commit ffdbada
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion streamjoy/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def validate_xarray(
dim: str | None = None,
var: str | None = None,
warn: bool = True,
raise_ndim: bool = True,
):
import xarray as xr

Expand All @@ -262,7 +263,7 @@ def validate_xarray(

squeeze_dims = [d for d in ds.dims if d != dim and ds.sizes[d] == 1]
ds = ds.squeeze(squeeze_dims)
if ds.ndim > 3:
if ds.ndim > 3 and raise_ndim:
raise ValueError(f"Can only handle 3D arrays; {ds.ndim}D array found")
return ds

Expand Down
2 changes: 1 addition & 1 deletion streamjoy/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def serialize_xarray(
dim = kwargs.pop("dim", None)
var = kwargs.pop("var", None)

ds = _utils.validate_xarray(ds, dim=dim, var=var)
ds = _utils.validate_xarray(ds, dim=dim, var=var, raise_ndim=renderer is None)
if not dim:
dim = list(ds.dims)[0]
_utils.warn_default_used("dim", dim, suffix="from the dataset")
Expand Down

0 comments on commit ffdbada

Please sign in to comment.