Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Dec 19, 2023
1 parent 1933e0b commit a4bda14
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,3 +1746,20 @@ def test_new_index_var_computes_once():
data = dask.array.from_array(np.array([100, 200]))
with raise_if_dask_computes(max_computes=1):
Dataset(coords={"z": ("z", data)})


def test_minimize_graph_size():
import cloudpickle

# regression test for https://github.com/pydata/xarray/issues/8409
ds = Dataset(
{"foo": (("x", "y", "z"), dask.array.ones((120, 120, 120)))},
coords={"x": np.arange(120), "y": np.arange(120), "z": np.arange(120)},
).chunk(x=20, y=20, z=1)

actual = len(cloudpickle.dumps(ds.map_blocks(lambda x: x)))
expected = len(cloudpickle.dumps(ds.drop_vars(ds.dims).map_blocks(lambda x: x)))

# prior to https://github.com/pydata/xarray/pull/8412
# actual is ~5x expected
assert actual < 2 * expected

0 comments on commit a4bda14

Please sign in to comment.