Skip to content

Commit

Permalink
Test broadcast-trick logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gjoseph92 committed Feb 1, 2022
1 parent 883c8fa commit 1b03d4b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion stackstac/tests/test_to_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import hypothesis.extra.numpy as st_np
import numpy as np
from rasterio import windows
import dask.core
import dask.threaded
from dask.array.utils import assert_eq

from stackstac.raster_spec import Bbox, RasterSpec
Expand Down Expand Up @@ -171,7 +173,17 @@ def __setstate__(self, state):
assert arr.dtype == dtype_

assert_eq(arr, results, equal_nan=True)
# TODO test broadcast-trick chunks

# Check that entirely-empty chunks are broadcast-tricked into being tiny.
# NOTE: unfortunately, this computes the array again, which slows down tests.
# But passing a computed array into `assert_eq` would skip handy checks for chunks, meta, etc.
TestReader.opened.clear()
chunks = dask.threaded.get(arr.dask, list(dask.core.flatten(arr.__dask_keys__())))
for chunk in chunks:
if (
np.isnan(chunk) if np.isnan(fill_value_) else np.equal(chunk, fill_value_)
).all():
assert chunk.strides == (0, 0, 0, 0)


@given(
Expand Down

0 comments on commit 1b03d4b

Please sign in to comment.