Skip to content

Commit 0dff7cf

Browse files
authored
In mosaic, ignore axis if dim is given (#149)
1 parent b0e7b6e commit 0dff7cf

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

stackstac/ops.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def mosaic(
174174
dim:
175175
The dimension name to mosaic. Default: None.
176176
axis:
177-
The axis number to mosaic. Default: 0. Only one of
178-
``dim`` and ``axis`` can be given.
177+
The axis number to mosaic. Default: 0. If ``dim`` is given, ``axis``
178+
is ignored.
179179
reverse:
180180
If False (default), the last item along the dimension is on top.
181181
If True, the first item in the dimension is on top.
@@ -207,6 +207,8 @@ def mosaic(
207207
f"since {nodata} cannot exist in that dtype. "
208208
)
209209

210+
axis = None if dim is not None else axis
211+
210212
func = (
211213
partial(_mosaic_dask, split_every=split_every)
212214
if isinstance(arr.data, da.Array)

stackstac/tests/test_mosaic.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ def test_mosaic_dtype_error(dtype: np.dtype):
4646
st_stc.raster_dtypes,
4747
st_np.array_shapes(max_dims=4, max_side=5),
4848
st.booleans(),
49+
st.booleans(),
4950
)
5051
def test_fuzz_mosaic(
51-
data: st.DataObject, dtype: np.dtype, shape: Tuple[int, ...], reverse: bool
52+
data: st.DataObject, dtype: np.dtype, shape: Tuple[int, ...], reverse: bool, use_dim: bool,
5253
):
5354
"""
5455
See if we can break mosaic.
@@ -73,8 +74,13 @@ def test_fuzz_mosaic(
7374
split_every = data.draw(st.integers(1, darr.numblocks[axis]), label="split_every")
7475
xarr = xr.DataArray(darr)
7576

77+
if use_dim:
78+
kwargs = dict(dim=xarr.dims[axis])
79+
else:
80+
kwargs = dict(axis=axis)
81+
7682
result = mosaic(
77-
xarr, axis=axis, reverse=reverse, nodata=fill_value, split_every=split_every
83+
xarr, reverse=reverse, nodata=fill_value, split_every=split_every, **kwargs
7884
)
7985
assert result.dtype == arr.dtype
8086
result_np = mosaic(xr.DataArray(arr), axis=axis, reverse=reverse, nodata=fill_value)

0 commit comments

Comments
 (0)