Skip to content

Commit

Permalink
Ignore axis if dim is given and test passing dim to mosaic gjoseph92#148
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan committed Apr 30, 2022
1 parent b0e7b6e commit f069da9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions stackstac/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def mosaic(
dim:
The dimension name to mosaic. Default: None.
axis:
The axis number to mosaic. Default: 0. Only one of
``dim`` and ``axis`` can be given.
The axis number to mosaic. Default: 0. If ``dim`` is given, ``axis``
is ignored.
reverse:
If False (default), the last item along the dimension is on top.
If True, the first item in the dimension is on top.
Expand Down Expand Up @@ -207,6 +207,8 @@ def mosaic(
f"since {nodata} cannot exist in that dtype. "
)

axis = None if dim is not None else axis

func = (
partial(_mosaic_dask, split_every=split_every)
if isinstance(arr.data, da.Array)
Expand Down
10 changes: 8 additions & 2 deletions stackstac/tests/test_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def test_mosaic_dtype_error(dtype: np.dtype):
st_stc.raster_dtypes,
st_np.array_shapes(max_dims=4, max_side=5),
st.booleans(),
st.booleans(),
)
def test_fuzz_mosaic(
data: st.DataObject, dtype: np.dtype, shape: Tuple[int, ...], reverse: bool
data: st.DataObject, dtype: np.dtype, shape: Tuple[int, ...], reverse: bool, use_dim: bool,
):
"""
See if we can break mosaic.
Expand All @@ -73,8 +74,13 @@ def test_fuzz_mosaic(
split_every = data.draw(st.integers(1, darr.numblocks[axis]), label="split_every")
xarr = xr.DataArray(darr)

if use_dim:
kwargs = dict(dim=xarr.dims[axis])
else:
kwargs = dict(axis=axis)

result = mosaic(
xarr, axis=axis, reverse=reverse, nodata=fill_value, split_every=split_every
xarr, reverse=reverse, nodata=fill_value, split_every=split_every, **kwargs
)
assert result.dtype == arr.dtype
result_np = mosaic(xr.DataArray(arr), axis=axis, reverse=reverse, nodata=fill_value)
Expand Down

0 comments on commit f069da9

Please sign in to comment.